Solved

Searching Data Using servlets in a database

Posted on 2002-03-29
1
144 Views
Last Modified: 2013-11-24
Lets say you hava data in a database and you want a user to enter some text from the html page and then the servlet would be able  to carryout the searching and then give the user the found or no found message e.g. search for an customerId in a database. Provide a example / sample code.
0
Comment
Question by:wbmorapedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
rashidkamranbs earned 65 total points
ID: 6905655
let suppose you have customerID text field in ur HTML form that is submitted to a servlet name Find the post method could be (ignore little typo)

public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
  String customerID=req.getParameter("customerID");
  Connection cn=.... code to get Connection ....
  Statement st=cn.createStatement();
  ResultSet rs=st.executeQuery("select customerID from Customer where customerID='"+customerID+"'");
 if(rs.isBeforeFirst())
   res.getWriter().print("Record Found");
 else
   res.getWriter().print("Record Not Found");
 cn.close();
}

this is not perfect.. ya need to handle all the exceptions etc..  ur question was quite open infact :-)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 45
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 96
Running JavaFX on the Raspberry Pi 27 299
JDBC performance 8 35
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question