选择nowait更新

时间:2015-02-20 19:16:30

标签: java oracle select

我的客户需要在数据库中完成大量更新。我已经完成了试图说服他们这可以更干净地完成。他们希望运行一个带有"的select语句,用于更新nowait"在选择的行上然后他们想要运行更新语句。我尝试了很多方法但是我遇到了错误。

String selectQuery = " Select * from " + table + " where column=\'" + column + "\' FOR UPDATE NOWAIT";
String updateQuery = " UPDATE " + table + " SET newcolumn = \'" + newValue + "\' WHERE column = \'" + column + "\' ";

Connection connection = null;       

try 
{           
    connection = DriverManager.getConnection(dbURL, dbUsername, dbPassword);

    Statement stmt = connection.createStatement();
    stmt.addBatch(selectQuery);
    stmt.addBatch(updateQuery);
    stmt.addBatch(commit);
    int [] updateCounts = stmt.executeBatch();
    stmt.close();
}

这会有例外:

invalid batch command: invalid SELECT batch command 0
26736 [Thread-11_DataConversion] ERRORDTL - [1424462365738]java.sql.BatchUpdateException: invalid batch command: invalid SELECT batch command 0
    at oracle.jdbc.driver.OracleStatement.executeBatch(OracleStatement.java:4462)
    at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
    at .BatchTokenizationAgent.executeJob(BatchTokenizationAgent.java:246)
    at com.yantra.ycp.agent.server.YCPAbstractAgent.executeOneJob(YCPAbstractAgent.java:392)
    at com.yantra.ycp.agent.server.YCPAbstractAgent.processMessage(YCPAbstractAgent.java:294)
    at com.yantra.ycp.agent.server.YCPAbstractAgent.run(YCPAbstractAgent.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

我也尝试过:

String selectQuery = " Select * from " + table + " where column=\'" + column + "\' FOR UPDATE NOWAIT; UPDATE " + table + " SET newcolumn = \'" + newValue + "\' WHERE column = \'" + column + "\' ";

Connection connection = null;       

try 
{           
    connection = DriverManager.getConnection(dbURL, dbUsername, dbPassword);

    Statement stmt = connection.createStatement();
    stmt.execute(selectQuery);
    stmt.execute(updateQuery);
    stmt.close();
}

这会有例外:

java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:194)
    at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:853)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)

有人可以指出正确的方向吗?非常感谢。这是一次性的工作,只需要在最少的工作量下工作。

0 个答案:

没有答案