Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

querying a database within a servlet

 
April Benzine
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to execute a query in a servlet. I have a connection.

--a static html page--
The user clicks on a radio button for one of the following this is all in a form and the form works)
id
lastName
firstName
dept

Then there is a text box to enter in criteria(This works too)
Then they click submit and it takes them to my results.java page (this works)

---results.java---(servlet)
In my init method I have my employeeSearch object instantiated and loaded.
(this makes a connection and does a test query)- this works

???Now I have to run a query on the database. How do I do this?
I know this goes in my doGet method. Please help me.
Thank You
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No what you know is not right, sorry. Ofcourse you can so that but you should not. It is strongly discouraged.

Please make your servlet and your jdbc code seperate. Servlet should be just to entertain the requests and giving responses. You can do your jdbc stuff in simple, normal java class.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
April,
Have you seen the JDBC tutorial from Sun?

It walks you through how to get started with JDBC. And Adeel is correct that it is best not to put the JDBC in the servlet. The servlet would instead call your database class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic