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
.