aspose file tools*
The moose likes JDBC and the fly likes connection pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection pooling " Watch "connection pooling " New topic
Author

connection pooling

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I have a jsp file that uses connection pooling via
<sql:query var="rs" dataSource="jdbc/jsps"> - it does work, and I also have a .java file that provides access to my database. This .java file works fine when I use Class.forName(...) and DriverManager.getConnection(....), but as I understand this approach doesn't implement connection pooling - I'd like to use connection pooling. When I use connection pooling components (the code I'm posting), nothing happens - the jsp files that use this.java file never load up, as if the browser can't diagest something. Since the browser doesn't give errors and the .java file compiles fine, I can't tell what's happening.
What is it? Thanks in advance.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Liliya,
It could be almost anything. So to narrow down the problem, do you know which line is causing the problem? You can tell by commenting out the lines after it. Another thing to try is to use a try/catch block and print out the exception. Or if it is a compiler error, check the logs for the error.

Note that it is generally considered good practice to keep database code out of the JSP. This makes the code more maintainable and facilitates troubleshooting problems like these. Instead, do the database calls from a servlet or at least a Java 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
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Thanks for responding. I wasn't able to detect any sort of failure in my DBUtil.java file. But after looking at MySQL pages for driver installation and looking at some examples code I have two concerns that might help me figuring out the problem. First question has to do with my DBUtil.java file - Does it HAVE to be a servlet to implement connection pooling? - because at this point my DBUtil.java file is just a class, ie public class DBUtil{...}
The second question has to do with server.xml tag <Resource name="jdbc/bla" .../> - The name parameter can be anything or does it have to reflect a name of a particular database?
I appreciate your help. Thanks in advance.
[ December 01, 2006: Message edited by: liliya woland ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Liliya,
No, it doesn't have to a servlet. Any class run in a web or ejb container can access the InitialContext without doing anything extra. Since your Java class is called from a JSP or servlet, it is in the web container.

jbc/bla is a reference to a datasource. The name needs to be the same in the code as on the server. However, you are free to name if anything you want. Many servers let you test the connection from an admin type console so you can verify it is configured correctly.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Well, I did more line by line testing and it appears to me that the execution of my DBUtil.java file freezes when it gets to line
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Liliya,
When you say it freezes, does that mean it hangs or that the JSP stops loading? Try putting it in a try/catch block to see what exception is getting thrown. Then post that here if it isn't clear what it means.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hi Jeanne, thank you for helping me. I have the statement in the try/catch block already. The browser attemps to open the page and after about 10 min of this, in IE7, it stops and the old page remains to be opened, but Firefox browser doesn't give up loading the page - I have to stop page loading for it to quit.
I'll post here what I have in the try/catch.


[ December 05, 2006: Message edited by: liliya woland ]
[ December 05, 2006: Message edited by: liliya woland ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Liliya,
Hmm. You are hitting the browser timeout. (Firefox doesn't have a timeout that I know of. It will happily wait a really long time.)

So to restate the problem, datasource.getConnection() is hanging. Maybe the pool is out of connections? Is any other application using that datasource? If so, does it close the connections when done with them?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection pooling