我最近发现以下程序中使用的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)
接口Statement,Connection和ResultSet最终由第三方JDBC驱动程序提供程序实现.
假设您使用的是MySQL驱动程序,这就是实现层次结构的方式,
内部实施层次:
com.mysql.jdbc.StatementImpl(Class) -->implements--> com.mysql.jdbc.Statement(interface) -->extends--> java.sql.Statement(interface)
内部实施层次:
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)
内部实施层次:
com.mysql.jdbc.ResultSetImpl(Class) -->implements--> com.mysql.jdbc.ResultSetInternalMethods(Interface) -->extends--> java.sql.ResultSet(Interface)
| 归档时间: |
|
| 查看次数: |
9735 次 |
| 最近记录: |