将值从一个db更新到另一个db时获取'com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException'

时间:2018-04-20 09:31:27

标签: java mysql jdbc

我有两个数据库连接(broConn和zroConn),我正在将列值从第一个DB的一个表更新到第二个DB的相应表。两个表都具有相同的模式。

String sql = "select * From Personal_Info";
stmt = broConn.prepareStatement(sql);
ResultSet rs =  stmt.executeQuery(sql);
while (rs.next())
{
    String sql1 = "UPDATE personal_info SET Score = ?, Result = ?,
           ModifiedBy = ?, ModifiedDate = ?, StartDate = ?,
               EndDate = ?, UploadState = ?" + " WHERE CandidateID = ?";

    stmt = zroConn.prepareStatement(sql1);
    stmt.setInt(1, rs.getInt(8));
    stmt.setString(2, rs.getString(9));
    stmt.setString(3, rs.getString(15));
    stmt.setDate(4, rs.getDate(16));
    stmt.setDate(5, rs.getDate(17));
    stmt.setDate(6, rs.getDate(18));
    stmt.setString(7, rs.getString(19));
    stmt.setInt(8, rs.getInt(1));
    stmt.executeUpdate(sql1);
}

我在stacktrace中遇到错误 -

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 '?, Result = ?, ModifiedBy = ?, ModifiedDate = ?, StartDate = ?, EndDate = ?, Upl' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.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:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
    at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1540)
    at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2595)
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1468)
    at com.company.testdata.UpdateZRODB.main(UpdateZRODB.java:72)

0 个答案:

没有答案