I recently found out that the Statement, Connection and the ResultSet used in the following program are interfaces. This program works completely fine but who implements these interfaces ?
package jdbc;
import java.sql.*;
public class Mango {
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@66.66.66.128:1521:xe","SYSTEM","matrix");
Statement comm = con.createStatement();
comm.executeQuery("insert into a values('a',1)");
ResultSet res = comm.executeQuery("SELECT * FROM A");
comm.executeQuery("insert into a values('a',1)");
while(res.next()) {
System.out.println(res.getString(1) + " " + res.getInt(2));
}
}
}
Interfaces Statement, Connection and the ResultSet are finally implemented by the third party JDBC Driver provider.
Suppose if you are using MySQL Driver, this is how the hierarchy of implementation follows,
Internal implementation hierarchy:
com.mysql.jdbc.StatementImpl(Class) -->implements--> com.mysql.jdbc.Statement(interface) -->extends--> java.sql.Statement(interface)
Internal implementation hierarchy:
com.mysql.jdbc.JDBC4Connection(Class) -->extends--> com.mysql.jdbc.ConnectionImp(Class) -->extends--> com.mysql.jdbc.ConnectionPropertiesImpl(Class) -->implements--> com.mysql.jdbc.MySQLConnection(Interface) -->extends--> com.mysql.jdbc.Connection(Interface) -->extends--> java.sql.Connection(Interface)
Internal implementation hierarchy:
com.mysql.jdbc.ResultSetImpl(Class) -->implements--> com.mysql.jdbc.ResultSetInternalMethods(Interface) -->extends--> java.sql.ResultSet(Interface)
The JDBC API is implemented through the JDBC driver which are being provided by the various Database software vendors.
The JDBC Driver is a set of classes that implement the JDBC interfaces to process JDBC calls and return result sets to a Java application
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