File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes jdbc servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc servlet" Watch "jdbc servlet" New topic

jdbc servlet

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi everyone
i am new to java.i have a query regarding login in my project
when user is registered member of my site and he will login how
the comparison for matching the existing userid and password from jdbc will be done by using servlets and jdbc?
please i need help.
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
hi rahul,

in the service method of the servlet, using getParameter method of ServletRequest u can retrieve the username and password and compare to any value.
Here is a sample example:
//program for verifying username and password
//entered by the user
import javax.servlet.*;
public class signin extends GenericServlet
public void service(ServletRequest req,ServletResponse res)
String username=req.getParameter("uname");
String password=req.getParameter("pwd");
ServletOutputStream sos=res.getOutputStream();
if((username.equals("admin")) && (password.equals("rsandeep")))
sos.println("<center>Login Succesful</center>");
sos.println("Your username: "+username+"");
sos.println("Your Password: "+password+"");
sos.println("<head><title>Verify your username and password</title></head>");
sos.println("<center>Login Unsuccesful. Try again, by clicking your browser's back button.</center>");
catch(Exception e)
} // end of service
} // end of class
Here i have verified the username and password manually, u can do it with JDBC also.
first retrieve the username and password using select query and store it in a resultset, and using getString method of resultset store the username and password in String variables and then u can compare as above.
try it and get back!!!
Good luck..
I agree. Here's the link:
subject: jdbc servlet
It's not a secret anymore!