0

I have this code;

String sql = "UPDATE Players SET Losses=Losses+1 WHERE UUID='" + p.getUniqueId() + "';"; 
stmt.executeUpdate(sql);

How can I get the current Losses for a specific Player p?

4 Answers 4

1

SELECT query will return it, but what's your real question?

String sql ="SELECT column_name,column_name FROM table_name WHERE column_name ="" ;";

Sign up to request clarification or add additional context in comments.

Comments

1

I would use a Select for Update, and something like this -

String query = "SELECT Losses FROM Players FOR UPDATE "
               + "Players SET Losses=Losses+1 WHERE UUID=?";
ps = conn.prepareStatement(query,
                       ResultSet.TYPE_FORWARD_ONLY,
                       ResultSet.CONCUR_UPDATABLE);
ps.setString(1, p.getUniqueId());
ResultSet rs = ps.executeQuery();
int losses = 0;
if (rs.next()) {
  losses = rs.getInt("Losses");
}

Comments

0

You can get the losses like the following. Seems really trivial, guess you are an absolute beginner.

String sql = "SELECT Losses FROM Players WHERE UUID='" + p.getUniqueId() + "';"; 
ResultSet rs = stmt.executeQuery(sql);
int losses = -1;
if(rs.next()) {
    losses = rs.getInt("Losses");
}

Comments

0

You'd have to make a SELECT statement. Like SELECT losses FROM Players WHERE UUID='"+p.getUniqueId()+"';"; Then use Statement's executeQuery() which returns a ResultSet. You can use an iterator to extract the data from the ResultSet object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.