I have this code here:
private void updateGame(String column, String player, String block, String state) {
try {
Connection conn = db.openConnection();
PreparedStatement ps = conn.prepareStatement("UPDATE games SET ? = ? WHERE game_id = ?");
ps.setString(1, column);
ps.setString(2, block);
ps.setInt(3, getGameId(state, player));
ps.executeUpdate();
conn.close();
} catch (Exception ex) {
}
}
When I pass in the column parameter, I want it to update a specific column in the database that I wrote when calling the function. I have multiple columns that are similar and that's why I am using this method. However, when I do it this way, it just gives out an error. I tried setting the column directly, without a question mark (?), and it worked. Not a duplicate because of the reply i got that is a different solution to the one in the "duplicate"
Is there any way to do this?