Reputation: 13
Hello!
I'm new in handling MySQL databases in Java. So, my problem is, I want to get an Integer out of my Database.
So, that's my method to get an ResultSet:
public static ResultSet getResult(String syntax) {
try {
PreparedStatement statement = con.prepareStatement(syntax);
return statement.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
And here is my how I call the method above:
ResultSet rs = MySQL.getResult("SELECT playedtime FROM ffa_playerdata WHERE UUID='"
+ p.getUniqueId().toString() + "'");
So, how can I make an Integer out of that? Thank a lot!
Upvotes: 0
Views: 41
Reputation: 23329
You can use getInt
if(resultSet.next()){
Integer result = resultSet.getInt("playedtime");
}
And btw, use PreparedStatment instead of string concatenation for constructing the query, it is safer and cleaner.
Upvotes: 1