I have a question about SQLite in bukkit encoding. I'm trying to figure out how to find a player in the database using a UUID and change values (such as the number of tokens) on the same line. I'm using a prepared statement and I've tried this, but I don't know what to do with it. Would anyone be willing to try to advise me? Thank you.
Connection conn = null;
PreparedStatement ps = null;
PreparedStatement find = null;
ResultSet rs = null;
try {
conn = getSQLConnection();
find = conn.prepareStatement("SELECT * FROM " table " WHERE player = '" uuid "';");
ps = conn.prepareStatement("REPLACE INTO " table " (cookies) VALUES(?)");
rs = find.executeQuery();
while(rs.next()){
if(rs.getString("player").equals(uuid)){
ps.setInt(1,cookies);
}
}
ps.executeUpdate();
find.executeUpdate();
return;
} catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally {
try {
if (ps != null)
ps.close();
if (conn != null)
conn.close();
} catch (SQLException ex) {
plugin.getLogger().log(Level.SEVERE, Errors.sqlConnectionClose(), ex);
}
}
return;
}
CodePudding user response:
You can use a single UPDATE
statement:
try {
conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " table " SET cookies = ? WHERE player = ?;");
ps.setString(1, cookies);
ps.setString(2, uuid);
ps.executeUpdate();
} ....
I assumed that the column that you want to update is cookies
.
CodePudding user response:
What about update query? You can select with the where clauses which rows to update.