-2
try {
    String strQry= "CREATE TABLE IF NOT EXISTS ERROR_DETAIL (\"SNO\"NUMBER(16,0),\"TABLE_NAME\"  VARCHAR2(32 BYTE),\"ERROR_DESC\" VARCHAR2(255 BYTE),\"XCOORDINATE\" FLOAT(126),\"YCOORDINATE\" FLOAT(126),\"STATUS\"  VARCHAR2(30 BYTE),\"COMMENT\" Varchar2(255 Byte),PRIMARY KEY (\"TABLE_NAME\", \"ERROR_DESC\") ENABLE);";
    stmt = con.createStatement();
    stmt.execute(strQry);

} catch (Exception e) {
    e.printStackTrace();
}

此代码给出错误:

java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option

但相同的查询在 oracle 中正常工作

4

2 回答 2

0

Print the content of your strQry variable, and you'll see that it's not valid:

  • you don't need double quotes around column names
  • you should have a space between each column name and its type
  • you shouldn't have a semi-colon at the end of the query

Moreover, I think you should use executeUpdate() and not execute().

于 2012-06-07T13:01:53.460 回答
0

尝试使用下面的代码。

try {
    String strQry= " CREATE TABLE IF NOT EXISTS ERROR_DETAIL (SNO NUMBER(16,0),TABLE_NAME VARCHAR2(32 BYTE),ERROR_DESC VARCHAR2(255 BYTE),XCOORDINATE FLOAT(126),YCOORDINATE FLOAT(126),STATUS VARCHAR2(30 BYTE),COMMENT Varchar2(255 Byte),PRIMARY KEY (TABLE_NAME, ERROR_DESC) ENABLE)";
    stmt = con.createStatement();    
    stmt.execute(strQry);                    

} catch (Exception e) { e.printStackTrace(); }

更改只是删除;里面的“(即在给定的代码中它是启用的);”;

我将其更改为启用)";

于 2014-11-06T08:14:41.760 回答