java 从SAP获取数据时,MySQL服务器版本中出现SQL语法错误

nhaq1z21  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(160)

我从SAP获取数据,并根据该响应更新MYSQL DB表中的标志。但我的查询每次都给我一个SQL语法错误(见下面的日志)。JAVA和SAP之间的连接正常。我可以将数据发送到SAP。它起作用了。

*tbl_po_data是我的MYSQL表。
***table.getName()**获取我的SAP表名。
*FLAG为SAP表标志字段。

这是我的方法。

private void tableOparator(Table table) throws Exception {

        pooler = DBPool_POSMS.getInstance();
        dataSource = pooler.getDataSource();
        Connection con = dataSource.getConnection();
        con.setAutoCommit(false);

        qex = new DBTableQueryExcecutre(con);

        for (int i = 0; i < table.getNumRows(); i++) {
            table.setRow(i);

            String sbQuery2 = "update tbl_po_data set status = 'X' where reference_no " + " in (SELECT REFNO from '"
                    + table.getName() + "' where FLAG = 'X')";

            int rcount = qex.runQuery(sbQuery2);
                System.out.println("tbl_po_data Rows -->" + rcount + "Status Updated");
                con.commit();

        }

        qex.closeConnections();

    }

我的LOGCAT

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ZSLPOSMSTBL' where FLAG = 'X')' at line 1
    at sun.reflect.GeneratedConstructorAccessor1.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
    at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
    at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
    at DBTableQueryExcecutre.runQuery(DBTableQueryExcecutre.java:52)
    at CreatePO.tableOparator(CreatePO.java:203)
    at CreatePO.sendDataToSap(CreatePO.java:170)
    at CreatePO.run(CreatePO.java:53)
    at java.util.TimerThread.mainLoop(Unknown Source)
    at java.util.TimerThread.run(Unknown Source)
3mpgtkmj

3mpgtkmj1#

您试图从字符串值'ZSLPOSMSTBL'中选择,而不是从表名ZSLPOSMSTBL中选择
删除SQL语句中的引号,它应该可以工作。

"update tbl_po_data set status = 'X' where reference_no " + " in (SELECT REFNO from "
                + table.getName() + " where FLAG = 'X');"

相关问题