到目前为止,我有这样的陈述:
String query = "UPDATE Score SET Points = "+scorecard[TOTAL][i]+" WHERE Name = "+players[i].getName()+" AND Lastname = "+players[i].getLastName()";
知道我应该怎么做吗?我看到某处使用CASE WHEN
语法,但无法使其正常工作。
答案 0 :(得分:2)
你想要
update score set points = ? where
name = ? and lastname = ?
and points < ?
作为SQL。请使用PreparedStatement。
try(PreparedStatement ps = con.prepareStatement("update score set " +
" points = ? where name = ? and lastname = ? and points < ?") {
ps.setInt(1, scorecard[TOTAL][i]);
ps.setString(2, players[i].getName());
ps.setString(3, players[i].getLastName());
ps.setInt(4, scorecard[TOTAL][i]);
ps.executeUpdate();
}