ERROR ON QUERYING ORACLE DB

谁都会走 提交于 2021-02-11 16:51:30

问题


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.


回答1:


Remove the below line

 CONSTRAINT person_pk PRIMARY KEY ('idNo')

Use the below line in your code instead

 CONSTRAINT person_pk PRIMARY KEY (idNo)



回答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')"
               + ");";


来源:https://stackoverflow.com/questions/23336843/error-on-querying-oracle-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!