当前位置: 代码迷 >> Eclipse >> JDBC 用参数identity(1,1)有关问题
  详细解决方案

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

热度:46   发布时间:2016-04-23 13:45:32.0
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 !
  相关解决方案