我正在使用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();
型
2条答案
按热度按时间2g32fytz1#
如果它帮助任何人,我已经纠正了这个问题,在我这边删除尾随分号(;)在DML的末尾。甲骨文似乎不喜欢它。
ut6juiuv2#
解决方案:
您需要使用
Statement
对象并创建它的示例来执行“创建global temporary
表”查询[createStatment
而不是prepareStatment
原因:
global temporary
不是从连接运行的有效DDL。PreparedStatment()修复:
字符串