我對 bukkit 編碼中的 SQLite 有疑問。我試圖弄清楚如何使用 UUID 在資料庫中查找玩家并在同一行上更改值(例如令牌的數量)。我正在使用準備好的宣告,我已經嘗試過了,但我不知道該怎么做。有人愿意嘗試建議我嗎?謝謝你。
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;
}
uj5u.com熱心網友回復:
您可以使用單個UPDATE陳述句:
try {
conn = getSQLConnection();
ps = conn.prepareStatement("UPDATE " table " SET cookies = ? WHERE player = ?;");
ps.setString(1, cookies);
ps.setString(2, uuid);
ps.executeUpdate();
} ....
我假設您要更新的列是cookies.
uj5u.com熱心網友回復:
更新查詢呢?您可以使用 where 子句選擇要更新的行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/468229.html
下一篇:ajax獲取查找資料屬性值的請求
