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));
}
System.out.println("con class is "+ con.getClass());
System.out.println("comm class is "+ comm.getClass());
System.out.println("res class is "+ res.getClass());
}
}
输出:
con class is class oracle.jdbc.driver.T4CConnection
comm class is class oracle.jdbc.driver.T4CStatement
res class is class oracle.jdbc.driver.OracleResultSetImpl
T4CConnection 实现接口 Connection T4CStatement 实现接口 Statement OracleResultSetImpl 实现接口 ResultSet
如果连接、语句和结果集是接口,我如何调用它们?我在这里读到我永远无法实例化接口,但请看这里的以下程序......