DriverManager versus JNDI?

I have written a servlet that drives all of my web applications. One of the core classes connects to a database to do security validation. Currently, I am using DriverManager to connect to the database. However, I am having an issue where it crashes the server (using Tomcat 4.x I believe) when I have concurrent users. I am not sure if it is the connection to the database that is a problem or not, but somebody still suggested that I perhaps use JNDI instead of DriverManager. What would the advantages be of doing this? I am relatively new to using and implementing JNDI, so any help or comments would be greatly appreciated.

Thanks!!!

Mike

[662 byte] By [mlukena] at [2007-9-23]
# 1

Hi Mike,

JNDI is used to create a context and create the Datasource. By creating datasource it will automatically participate in Connection pooling. Datasource can be modified once instead of modifying the driver manager setup in code. when moving the code to different server or changing the database usage of datasource will be reduce the pain.

thanks.

moe

manbalagan80a at 2007-7-11 > top of java,Core,Core APIs...
# 2

When using a JNDI . The Container lookup the datasource using JNDI and creates a set of connections before hand to serve the user. Now the user response will be fast and if the user forgets to disconnect the connection such as connection.close(). Then Container will automatically release the connection. More over user will never be connected to database directly and no user will have direct acess to database now every one will be having access to JNDI name bounded to that datasouce. So it is better to go for JNDI than directly connecting.

More over the number of cursors (Connections) provided that can be kept opened by the users on the database is limited by the vendor to safegaurd the crash. If you are using the SQL server then you can get that known as some were around 500 connection as default.

So if you use JNDI then the number connections will be limited and the the proper usage of resource can be take care of automatically.

ShivaKatulaa at 2007-7-11 > top of java,Core,Core APIs...