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

Servlet and JDBC

ppavya india

Joined: Sep 27, 2004
Posts: 19
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
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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!


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
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 ({
//show welcome message
//show error message

[ December 23, 2004: Message edited by: danny liu ]
I agree. Here's the link:
subject: Servlet and JDBC
It's not a secret anymore!