I am using the Interface Connection from the package java.sql
Actually I though it a Class but when I tried to look at the source code I figured out that it is an Interface.
In the source of the Connection interface there are only single line for each method without any implementation!!
What makes this interface works as it?
Database to connect to: MySql
Connection source code page: http://www.docjar.com/html/api/java/sql/Connection.java.html
It is not the interface that "works" but one of its implementations, which is specific to your particular RDBMS vendor. In fact, it is typically the vendor who provides the implementation of the Connection
interface.
When you call
Connection conn = DriverManager.getConnection(
"jdbc:jdbc:mysql://localhost:3306/
, connectionProps);
driver manager searches through registered JDBC drivers, finds the one for MySQL (it knows it's MySQL from the connection string), passes connection properties to the constructor of the class inside MySQL JDBC driver that implements Connection
, and returns the resultant Connection
instance back to you. For example, the driver may return an instance of a package-private class MySqlConnection
that implements Connection
, and your program would use it to interact with RDBMS without knowing any details about the class, other than the fact that it implements Connection
.
The MySQL driver (http://www.mysql.com/products/connector/) contains the actual implementation. The java.sql.Connection interface just defines the methods that the JDBC standard expects. Each database driver must define how to actually connect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With