Servlet Database Java source code
#1

Code:
import javax.servlet.*;
import java.sql.*;

public class ServletDatabase extends GenericServlet
{
    Connection con;
    PreparedStatement prst;
    ResultSer rs;
    public void init(ServletConfig sc)
    {
        try
        {
            Class.forName("jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("Jdbc:Odbc:stud","eml","");
            super.init(sc);
        }
        catch(Exception e)
        {
            System.out.println(e.getString());
        }
    }
    
    public void service(SrevletRequest req,ServletResponse res)
    {
        try
        {
            res.setContextType("text/html");
            String s1 = req.getParameter("login");
            String s2 = req.getParameter("password");
            prst = con.PreparedStatement("Select eno,ename,desig,sal from emp where    
                            login=? password=?");
            ServletOutputStream sos = res.getOutputStream();
            rs = prst.executeQuery();
            if(rs.next())
            {
                int eno = rs.getInt(3);
                String name = rs.getString(4);
                String desig = rs.getString(5);
                float sal = rs.getFloat(6);
                sos.println("Employee No"+eno);
                sos.println("Employee Name"+name);
                sos.println("Designation"+desig);
                sos.println("Salary"+sal);    
            }
            else
            {
                sos.println("You are not a valid user, please try again");
            }
        }
        
            
    }
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: bank management system project code in java servlet**ireless blackbox, w3 school servlet, servlet source code for online examination system in java, java database applicationdiagram, seminar report on servlet pdf, servlet session, java servlet arduino,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple Key Events Java source code smart paper boy 3 3,653 07-02-2017, 03:41 PM
Last Post: NARESHLAFOOT
  Window Events Java source code smart paper boy 1 3,716 02-03-2012, 10:48 AM
Last Post: seminar paper
  Inter net banking java source code smart paper boy 3 6,013 01-03-2012, 11:24 AM
Last Post: seminar paper
  UDP server java source code smart paper boy 1 3,860 05-01-2012, 05:50 PM
Last Post: jeslinapeter
  UDP client Java source code smart paper boy 2 3,729 12-12-2011, 09:56 AM
Last Post: seminar addict
  Text Demo Java source code smart paper boy 0 2,104 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Text Area Demo Java source code smart paper boy 0 2,117 30-08-2011, 12:44 PM
Last Post: smart paper boy
  server test Java source code smart paper boy 0 2,307 30-08-2011, 12:42 PM
Last Post: smart paper boy
  Ser To App java source code smart paper boy 0 1,707 30-08-2011, 12:39 PM
Last Post: smart paper boy
  SB Demo java source code smart paper boy 0 1,569 30-08-2011, 12:38 PM
Last Post: smart paper boy

Forum Jump: