Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Searching Data Using servlets in a database

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
A solution for Fortify Path Manipulation.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

824 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