• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Servlet and JDBC

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am new to servlet technology, I have created one table in SQL as "users" with column name as login, password, username and I have already added 5 records, I have also a html page where I have only two fields i.e. login and password. What I want to do, to ask user to put input as login and password and if the user enters same user name and password which I have already created in users table, then user'll get complete username, if he enters wrong input then he'll get an error message.
How to create servlet for these things. Any help would be appreciated
Thanx in advance
Posts: 17344
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Second Notice

"ppavya ppavya"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it


Thanks! and welcome to the JavaRanch!

Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you need to install a jdbc driver which can be accessed by your server.

Second, modify the servlet code to access database.

import java.sql.*;

public LoginServlet extends HttpServlet{

String account= request.getParameter("account");
String password = request.getParameter("password");
//connect to database

Class.forName(jdbcDriver name);
Connection con = DriverManager.getConnection(connection string);
PreparedStatement st = con.prepareStatement("select * from users " +
"where account=? and password=?");
ResultSet rsQuery = st.executeQuery();
if (rsQuery.next()){
//show welcome message
//show error message

[ December 23, 2004: Message edited by: danny liu ]
Normally trees don't drive trucks. Does this tiny ad have a license?
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!