문제

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