• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to search a db?

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic