wood burning stoves 2.0*
The moose likes JDBC and the fly likes Ned to change servlet code to pure java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Ned to change servlet code to pure java" Watch "Ned to change servlet code to pure java" New topic
Author

Ned to change servlet code to pure java

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi Friends,
I am trying to use the Tomcat Data Sources,connection pooling.The example I saw used servlets,can you please tell me how to change the servlet to equivalent java code,as i dont know servlets.I have marked(----) the statements,which need to be changed.I have marked the last one(return results),because I dont know where to fit that statement.


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Jas,
Connection pooling uses a datasource. This works if your class runs on the server (servlet, ejb, ...) It also works if a servlet or ejb is calling your class. If this is not the case, you need to substitute the part of the code that gets the connection with the DriverManager code (from your other post.)

As for returning the resultset, I'm not sure what the confusion is. Are you trying to process it?


[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
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Thanks jeanne again,
I have a jsp,which fires in the query to this class,which returns the resultset to another java class,which cooks the data and sends it back to the jsp.I have worked on the code,I just want to know when and where should I call the close() method.Here's my new code:
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Jas,
The close method looks good.

"which returns the resultset to another java class,which cooks the data" - This is the class that needs to call your newly written close method.
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Thanks Jeanne,
After making changes to Tomcat and configuring the connection pool,I am able to reduce the database access time vastly.But there is still a delay,how can i check the no.of connections that are open,because i am not calling the close routine anywhere.Please help me again.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Jas,
For that you need a profiling tool.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ned to change servlet code to pure java
 
Similar Threads
NullPointerException At Statement stmt = conn.createStatement();
not redirecting to main page
Statement Closed Error - please help
Database - how to increase the access time
cannot find symbol