سؤال

I am using oracle 10g and I wrote a create table query like this -

String UserTable="CREATE TABLE UserDetail ( \n" +
               "        idNo INT(64) NOT NULL , \n" +
               "        name VARCHAR(50),\n" +
               "        email VARCHAR(50),  \n" +
               "        state VARCHAR(50),\n"+
               "       country VARCHAR(50),\n" +                    
               "        CONSTRAINT person_pk PRIMARY KEY ('idNo')"
                   + ");";


          // Connection con2=DriverManager.getConnection(DbAddress,"vivek","123456");
           PreparedStatement st2=conn.prepareStatement(UserTable);
           st2.executeUpdate();
           conn.close();

but it gives following exception-

java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis

on syssout it the query becomes this -

CREATE TABLE UserDetail ( 
    idNo INT(64) NOT NULL , 
    name VARCHAR(50),
    email VARCHAR(50),  
    state VARCHAR(50),
   country VARCHAR(50),
   CONSTRAINT person_pk PRIMARY KEY (idNo)

);

please help.

هل كانت مفيدة؟

المحلول 2

oh I got the solution- I was using Int instead of Number and it was not supported. the query should be-

"CREATE TABLE UserDetail ( \n" +
           "        idNo NUMBER NOT NULL , \n" +
           "        name VARCHAR(50),\n" +
           "        email VARCHAR(50),  \n" +
           "        state VARCHAR(50),\n"+
           "       country VARCHAR(50),\n" +                    
           "        CONSTRAINT person_pk PRIMARY KEY ('idNo')"
               + ");";

نصائح أخرى

Remove the below line

 CONSTRAINT person_pk PRIMARY KEY ('idNo')

Use the below line in your code instead

 CONSTRAINT person_pk PRIMARY KEY (idNo)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top