Solved

Searching Data Using servlets in a database

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now