读书人

JDBC 用参数identity(1,1)有关问题

发布时间: 2012-03-18 13:55:38 作者: rapoo

JDBC 用参数identity(1,1)问题
我想identity(1,1) 参数 在create table 里。但是我程序 run不出来。请教哪里错了

Java code
    public static void main(String[] args) throws SQLException, ClassNotFoundException {        // Load the driver (registers itself)    try {        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");        // Section 2. Connect to the databse        Connection conn1; // An object of type connection        String dbUrl = "jdbc:odbc:JDBC_Demo_Data_Source";        String user = "";        String password = "";        conn1 = DriverManager.getConnection(dbUrl, user, password);        System.out.println("*** Connected to the database ***");                  PreparedStatement stmt1 = conn1 .prepareStatement(          "create table test (id int identity(1,1) not null,  myNum int null)"          ); // create the person table stmt1.execute();         stmt1.execute();         conn1.commit();        conn1.close();    } catch (SQLException E) {        System.out.println("SQLException: " + E.getMessage());        System.out.println("SQLState: " + E.getLocalizedMessage());        System.out.println("VendorError: " + E.getErrorCode());    } // End of catch


[解决办法]
primary key !

读书人网 >Eclipse开发

热点推荐