This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
In another thread, @bear said that one should always use a ConnectionPool. I can see the good reasons for that. But when I write a simple Java application, without all the complexity of servlets, JEE, containers, etc. there are no ConnectionPool support.
Besides choosing a connection pool, you'll need something which runs at program startup to start the pool running. I expect each pool implementation has something like that which should hopefully be documented. And you'll have to configure the pool. And you'll have to change your application's code (if it's already written) to get its connections from the pool rather then directly from the JDBC driver.
And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.
Bear Bibeault wrote:And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.
I tend to write a lot of utility programs, they will beat on the DBMS, read gigabytes of data, say for loading a complex tree of objects. If I'm going to use them, they are simple shell program driven. If I expect others, I'll use Swing and stick up a simple GUI.
But behind the startup facade, I use huge libraries of business logic that are also used in webapi with tomcat and lots of servlet stuff. Rarely is a "simple shell program" not using multiple threads, daemons, etc.
So the answer is "yes"
I want the same code to work with ten lines of Java from a shell, and tens of thousands of lines in a JEE container.
It was last year, I think, that I converted the Swing app which is my decade-long project to use a connection pool. However I didn't use one of the connection pools which you usually see recommended for web applications, because that seemed rather like getting a 40-foot flatbed truck to bring my groceries home from the store.