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

connection pooling

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic