java.sql.SQLSyntaxErrorException:ORA-00922:选项丢失或无效

时间:2019-05-17 07:21:31

标签: java database oracle jdbc ojdbc

我正在使用java jdbc在Oracle DB中创建一个新表,并最终出现丢失或无效的选项。这样就不知道查询中出了什么问题

我尝试在SQL Plus和SQL Developer中运行相同的查询,但运行正常,但通过java jdbc运行时会抛出上述错误。这也是从Java代码中提取的内容。为此使用executeUpdate()方法。

CREATE TABLE EventTable (
    "EVENTID" NUMBER, "MODULE" NVARCHAR2(512),"EVENTTYPE" NVARCHAR2(512),
    "MODULEANDEVENTTEXT" NVARCHAR2(512), "TIME" TIMESTAMP (6), "SOURCE" NVARCHAR2(512),
    "SEVERITY" NVARCHAR2(512), "NODE" NVARCHAR2(512), "ACKNOWLEDGED" NUMBER(*,0),
    "USERSID" NVARCHAR2(512), "DID" NVARCHAR2(512), "MID" NVARCHAR2(512), "FH" NVARCHAR2(512),
    "LD" NVARCHAR2(512), "TD" NVARCHAR2(512), "ED" NVARCHAR2(512), "UD" NVARCHAR2(512), 
    "GD" NVARCHAR2(512), PRIMARY KEY ("EVENTID")
); 

java.sql.SQLSyntaxErrorException:ORA-00922:缺少或无效的选项

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:943)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:4875)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1361)

Java代码段

 countQuery.append(
                "CREATE GLOBAL TEMPORARY TABLE EventTable ( \"EVENTID\" NUMBER,  \"MODULE\" NVARCHAR2(512),\"EVENTTYPE\" NVARCHAR2(512), \"MODULEANDEVENTTEXT\" NVARCHAR2(512), \"TIME\" TIMESTAMP , \"SOURCE\" NVARCHAR2(512), \"SEVERITY\" NVARCHAR2(512), \"NODE\" NVARCHAR2(512), \"ACKNOWLEDGED\" NUMBER(*,0), \"USERSID\" NVARCHAR2(512), \"DESKTOPID\" NVARCHAR2(512), \"MACHINEID\" NVARCHAR2(512), \"FOLDERPATH\" NVARCHAR2(512), \"LUNID\" NVARCHAR2(512), \"THINAPPID\" NVARCHAR2(512), \"ENDPOINTID\" NVARCHAR2(512), \"USERDISKPATHID\" NVARCHAR2(512), \"GROUPID\" NVARCHAR2(512), PRIMARY KEY (\"EVENTID\")); "); 

PreparedStatement stmt = connection.prepareStatement(countQuery);

stmt.executeUpdate();

1 个答案:

答案 0 :(得分:0)

解决方案:

您将需要使用Statement对象并创建其实例以执行“创建global temporary表”查询 [createStatment而非prepareStatment

原因:

global temporary是无效的DDL,无法从connection.PreparedStatment()

运行

修复:

Statement stmt = con.createStatement();
stmt.executeUpdate(countQuery)