引用了包java.sql.*;
然后使用Connection c = new Connection();
编译时出错
Connection 是 abstract的,如何解决谢谢大家

解决方案 »

  1.   

    Connection是一个Interface,不能用它生成对象的
    这是连接Access数据库的
     String url = "jdbc:odbc:%odbcsourcename%";
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection conn = DriverManager.getConnection(url, "username", "password");
    这是连接SQL数据库的
                 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                            Connection conn = DriverManager.getConnection(
                 "jdbc:microsoft:sqlserver://localhost:1433", "username",
                                    "password");
      

  2.   

    谢谢你,在网上看到了这些代码,Connection c = new Connection();不就是生成对象吗Connection c = new Connection();
    c.setConnectionString ("dsn=aDSNName;pwd=aName;pwd=aPWD;database=aDatabase");
    c.setCommandTimeout (10);
    c.setConnectionTimeout (10);
    c.setCursorLocation (AdoEnums.adUseClientBatch);c.open();
    c.setDefaultDatabase ("aSpecificDatabase");
    System.out.println ("Connection string = " + c.getConnectionString());// Verify that the propertiea on the connection 
    // were set correctly. If not, return a fail condition.
    if (c.getCommandTimeout() != 10)
    return false;if (c.getConnectionTimeout() != 10)
    return false;if (c.getCursorLocation() != AdoEnums.adUseClientBatch)
    return false;if (c.getMode() != AdoEnums.adModeUnknown)
    return false;// Create a new Recordset to contain the results 
    // of the SQL DML operation (select * ...). 
    Recordset rs= c.execute ("select * from authors");
    rs.moveFirst();
    rs.moveLast();// Delete all rows from the authors table. 
    c.executeUpdate ("delete from authors");// Close the Connection and Recordset. 
    rs.close();
    c.close();
    return true; 
    }