1
votes

The JDBC documentation from Oracle says that driver provider should implement DataSource interface, but in real project source file, I always see the DataSource come from 3rd, such as DBCP connection pool.

I wonder if MySQL driver in itself implements DataSource interface?

2

2 Answers

1
votes

If you are talking about Connector/J, it provides:

  • com.mysql.jdbc.jdbc2.optional.MysqlDataSource (which implements DataSource),
  • com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource (which implements ConnectionPoolDataSource)
  • com.mysql.jdbc.jdbc2.optional.MysqlXADataSource (which implements XADataSource)

So, as far as your question goes. Yes Connector/J provides implementations to the DataSource interface and conforms with JDBC specs.

But, as you are aware by your question and @Piotr's answer, most applications will never deal with those implementations directly. At least in ten years as a Java Developer I have never done that. Let the Java EE App Server handle connections for you, or install a third party connection pool if you are down to standalone applications.

0
votes

You can use native DataSource provided by JDBC driver, but what you usually do is you use a connection pool like DBCP, C3P0 or BoneCP.