Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to search a db?

 
Andrew Parker
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Parker
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Screaming fools! It's nothing more than a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!