Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Searching Data Using servlets in a database

Posted on 2002-03-29
1
Medium Priority
?
148 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 195 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

721 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