On Dec 3, 2003, at 6:59 PM, Kwok Peng Tuck wrote:


>But this means I still have to get a connection, create a statement, and execute a query or update on the statement >in every servlet where I want to use the connection. Yes, it locates the connection details (i.e., the JDBC >connection method, the database name, user and password) somewhere centrally so that I don't have to keep >
coding it, but all of the connection overhead still has to be dealt with in every servlet in a webapp.


The datasource solution that a few people in the list (including me :) ) have been asking you to look at provides a connection pool to your web application. In your code where you ask for a connection from JNDI, you are actually getting a connection from the pool, which is already setup. When you call the close() method of this connection, it is not actually destoryed but returned to the connection pool, ready to be used.



I'm sorry. When I said "connection overhead," I didn't mean the overhead of creating a Connection object, I meant the overhead of having to write all the code to create one. I understand that there's a connection pool in a central location, but getting a connection from that pool is no less complicated for the programmer than creating one from scratch.


I'm incredibly lazy. It seems that if I'm only going to be connecting to two or three databases in a webapp, it should be possible to maintain open connections to those databases somewhere so that anywhere in my webapp I can issue a statement that runs a SQL statement. In other words, I want to encapsulate the connection creation so that my other programs can just assume that it's done. This may not be possible, but it seems a reasonable OO thing to do.

Does that make more sense, or am I still just confused?

Todd


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to