This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Servlet and JDBC

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
e.g.,

import java.sql.*;

public LoginServlet extends HttpServlet{

doGet(request,response){
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=?");
st.setString(1,account);
st.setString(2,password);
ResultSet rsQuery = st.executeQuery();
if (rsQuery.next()){
//show welcome message
}
else{
//show error message
}
}


}
[ December 23, 2004: Message edited by: danny liu ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic