File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes querying a database within a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "querying a database within a servlet" Watch "querying a database within a servlet" New topic
Author

querying a database within a servlet

April Benzine
Greenhorn

Joined: Sep 23, 2004
Posts: 17
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: May 26, 2003
Posts: 30918
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: querying a database within a servlet