So is this a client application? DriverManager#getConnection() application and database usually talk to each other using the connection obtained with DriverManager#getConnection() ? If so, then you do not need JNDI to make the connection pool work. The only thing in question will be enough. For example, C3P0 or Apache Commons DBCP (I would recommend C3P0, DBCP is one-way). Just replace DriverManager#getConnection() with it.
Edit: Reply to your comments:
The server will talk to the database, and the clients will connect to the server, so I won’t know if this client application should be called.
I actually mean a simple Java application with vanilla coverage that does not run inside the Java EE container. Pascal put it better.
Actually, I'm a little confused about how pooling works, is each connection running on its own thread? is there any document / book to help me better understand these concepts with regard to unconnected joining?
To start, the connection pool opens the connection and holds it open until a timeout is configured. Pooling wraps / beautify a mix with its own implementation. A connection pool can simultaneously open and hold a configured number of connections. When you call getConnection() , it will immediately provide you with an already open connection. When you call close() on the connection, it will return the connection to the pool for future requests. This means that you still have to write JDBC code in the usual way: get and close Connection , Statement and ResultSet in the shortest possible area. Close all of them in the finally block. If your JDBC code is already well written, you really only need to replace DriverManager#getConnection() . Since you must open and close Connection in the same method block, it usually starts in the same thread. The connection pool will worry that Connection will not be received by another thread in the meantime, until your code calls close() on Connection .
You can find a good article here to understand how the connection pool works under the hood (take care: do not use it for production and do not set it on fire, just get the whole idea). For real work, use the existing carefully designed and reliable pooling structure.
source share