谁在这个java程序中实现了Connection,ResultSet和Statement接口?

Cyc*_*ops 3 java interface

我最近发现以下程序中使用的Statement,Connection和ResultSet是接口.这个程序完全正常但谁实现了这些接口?

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));
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

San*_*nge 6

接口Statement,Connection和ResultSet最终由第三方JDBC驱动程序提供程序实现.

假设您使用的是MySQL驱动程序,这就是实现层次结构的方式,

  1. java.sql.Statement接口最终由com.mysql.jdbc.StatementImpl类实现.

内部实施层次:

com.mysql.jdbc.StatementImpl(Class) -->implements--> com.mysql.jdbc.Statement(interface) -->extends--> java.sql.Statement(interface)

  1. java.sql.Connection接口最终由com.mysql.jdbc.JDBC4Connection类实现.

内部实施层次:

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)

  1. java.sql.ResultSet接口最终由com.mysql.jdbc.ResultSetImpl类实现.

内部实施层次:

com.mysql.jdbc.ResultSetImpl(Class) -->implements--> com.mysql.jdbc.ResultSetInternalMethods(Interface) -->extends--> java.sql.ResultSet(Interface)