java.sql.statement 是个接口.但是我们在使用时却可以直接实例化.
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
public class dbconn {  
  private Connection cn;
 
   public dbconn() throws ClassNotFoundException, SQLException
           { 
       DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
       cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","7720563");  
                   }
   public void sql() throws SQLException
     { 
 Statement stm = cn.createStatement();
 stm.execute("update students set name='wenjun',sexy='man'");
 stm.executeUpdate("delete  from students where id =1");   
             }
   public void close() throws SQLException{ 
   cn.close();  
       }
}
不是很了解.或许我太菜了.是不是在加载驱动的时候.把接口实现了?

解决方案 »

  1.   

    JAVA_HOME\src.zip 为源代码,查看便知:DriverManager 中 getConnection 函数声明如下:public static synchronized Connection getConnection(String url, 
    java.util.Properties info) throws SQLException {
      
            // Gets the classloader of the code that called this method, may 
    // be null.
    ClassLoader callerCL = DriverManager.getCallerClassLoader();        return (getConnection(url, info, callerCL));
        }
      

  2.   

    晕,还没写完就点错了..
    总之一句话,你看看src中的源代码就知道了.
      

  3.   

    驱动数据库厂商就是根据JDBC的接口规范编写的实现类当你加载注册一个数据库的驱动后进行数据库操作时,就会生成驱动里面的具体类的对象
     
    然后通过一个接口引用指向这个对象Statement stm = cn.createStatement();
    你可以通过rtti得到这个对象的具体类System.out.println(stm);我的机器上打印出来结果是:
    com.mysql.jdbc.Statement@bb7465
    很显然这个对象是属于com.mysql.jdbc.Statement类的
      

  4.   

    同上.这就像List list = new ArrayList()一样,
    Statement stm = cn.createStatement();它返回的是一个实现了Statement的类.