Skip to content

Tag: datasource

How does JDBC DataSource works?

I wondered how works method getConnection() at DataSource? I assume that DataSource calling DriverManager.getConnection every time when we call DataSource.getConnection with our properties that we setting in DataSource. Is that true? Answer The answers to your question can be deduced from the DataSource javad…

Java memory leak with a data source

I have heard many times that not closing database connections might lead to a memory leak. (For example in this article) I tried reproducing the same issue by getting a connection from org.apache.commons.dbcp2.BasicDataSource and not closing it. This is my code: I have repeated the same process almost 400 tim…

How do I manually configure a DataSource in Java?

I’m trying to follow Sun’s JDBC tutorial at http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html It gives the following example code: This code doesn’t compile because the DataSource interface has none of these methods, except for the getConnection() method invoked last. (Here…