Solved

Searching Data Using servlets in a database

Posted on 2002-03-29
1
143 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 213
custom annotations 9 42
couple of eclipse 5 46
Glassfish admin console not working 1 34
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 …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

828 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