1

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;

    } 
forpas
  • 160,666
  • 10
  • 38
  • 76
Romis Pejs
  • 87
  • 4

2 Answers2

2

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.

forpas
  • 160,666
  • 10
  • 38
  • 76
0

What about update query? You can select with the where clauses which rows to update.

  • I do not know how to do it, i am new in this, and i am trying to figure out how to create this type of data. Is it possible to give me some example ? Thank you very much. – Romis Pejs Apr 29 '22 at 12:11