| 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
|
 |
 |
|
|
subject: How to search a db?
|
|
|