aspose file tools
The moose likes Servlets and the fly likes How to search a db? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "How to search a db? " Watch "How to search a db? " New topic
Author

How to search a db?

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Hi,
I want to create a very simple search function on my jsp page which connects to servlet and mysql database.
I want to search the ID attribute of the Staff database and then list out it's record.
What is the algorithm to do it?
Thanks
Andrew
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
1. Write a bean that reads your database and formats a html table. (you need to do several things: load the mySQL driver, get a connection, query the database, format the table using the result set).
2. Use the bean in your jsp file.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Here is the JSP page:

Here is the method in Servlet:

I want to make a search for
Staff ID, Staff Name OR Staff Salary.
Once input either of these 3 fields, it will show display the result on the same jsp page.
But, how should I write the servlet:
while(pstmt.next())
out.println(pstmt.getInt(staff.getStaffID())+ ", " + pstmt.getString(staff.getStaffName()) + ", " + pstmt.getDouble(staff.getSalary()));

and those code in the JSP page?
Thanks for any help.
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to search a db?
 
Similar Threads
how to search values in database
how to diplay daynamic image in struts>
Present a query to a database.
how to reindex search
How to save a search criteria in struts 2.0 -- Urgent