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]

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.