0

I am trying to create table that has column that auto increments the user id column. When I use the below code I get this error:

Exception in thread "main" java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis

String sql = "CREATE TABLE DBUSER("
            + "USER_ID NUMBER(5) NOT NULL AUTO_INCREMENT, "
            + "USERNAME VARCHAR(20) NOT NULL, "
            + "CREATED_BY VARCHAR(20) NOT NULL, "
            + "CREATED_DATE DATE NOT NULL, " + "PRIMARY KEY (USER_ID) "
            + ")";         Statement stmt;
stmt = connection.createStatement();
stmt.executeUpdate(sql);
Qiu
  • 5,651
  • 10
  • 49
  • 56
Amp787
  • 11
  • 1
  • 1
    I presume you are using Oracle? There is no auto_increment - create a trigger. See http://stackoverflow.com/questions/11296361/how-to-create-id-with-auto-increment-on-oracle – copeg Apr 07 '15 at 20:47
  • What is your DB? Are you sure it supports `NUMBER(5)` as a type? Maybe try with `int` or other numeric type. – Pshemo Apr 07 '15 at 20:49
  • Oracle 11G. The number (5) works, but not the auto increment. – Amp787 Apr 07 '15 at 20:58

1 Answers1

1

It should work if you remove the auto-increment

CREATE TABLE DBUSER(
       USER_ID NUMBER(5) NOT NULL, 
       USERNAME VARCHAR(20) NOT NULL, 
       CREATED_BY VARCHAR(20) NOT NULL, 
       CREATED_DATE DATE NOT NULL,  
       PRIMARY KEY (USER_ID) 
        )

Auto increment is not supported in Oracle

Alex
  • 21,273
  • 10
  • 61
  • 73