> I was reading an article from jguru, > http://www.jguru.com/faq/view.jsp?EID=161, which had a ref to a posting > from May of 2000 that mentioned that one way to save time on database > connections was to have a connection instance variable that was used each > time to access the database. Is this an efficient/professional way to > access the database or is it better to have a connection pool and create a > new Connection variable each time you access the database?
I assume from a an instance variable you either mean a single instance shared across all requests or a new instance per request. Either approach is not particularly good. JDBC Connections are generally single threaded, so if you only have a single connection you need to synchronize all access to that connection thus creating a bottle neck. However creating one connection per request is also generally a bad idea as creating and closing database connections is expensive in terms of time and resources, so most WebApps will use pooling. > Also, i was looking at the examples from apache dbcp, and it had an > example using the DriverManager as well as an example using the > DataSource. I could not find any good explanations on the web that tell > the difference between the two. Is there an advantage for using one over > the other? DriverManager is largely deprecated now. It is a technique typically used by standalone clients who don't have access to a JNDI server. A DataSource is used to get access to a JDBC Connection from a JNDI server. This is (generally) a better idea as it gives the app server (or web server) more options. For example it can silently add pooling support without your knowledge. It's also easier from an administrative point of few as the connection is referenced by name rather than by classname which is what happens if you use the DriverManager. This again makes it easier for an administrator to swap drivers in and out. Kevin Jones Developmentor ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html