写入 mySQL 数据库时,出现以下错误:
java.sql.BatchUpdateException: Unknown column 'ALFA' in 'where clause'
这是我的java代码:
public void pushWinner(String game, String teamW) throws SQLException{
String[] t1 = game.split("-");
String statement = "update games set winner=(?) where team1 = "+t1[0]+" AND team2 = "+t1[1];
try (PreparedStatement pstmt = conn.prepareStatement(statement)) {
pstmt.setString(1, teamW);
pstmt.addBatch();
pstmt.executeBatch();
pstmt.close();
} catch (SQLException ex) {
System.out.println(ex);
}
}
我真的看不出 where 子句有什么问题...
编辑
看我的评论,忘了说“ALFA”是什么。
team1 和 team2 的数据类型都是 VARCHAR(45)。
最佳答案
试试这个:因为 column
team1
和 team2
的数据类型是 VARCHAR
所以用单引号
来比较。
queryString= "update games set winner=(?) where team1 = '"+t1[0]+"' AND team2 = '"+t1[1]+"'";
关于java - 批量更新异常 : Unknown column in where clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26064864/