我想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 !