I run a database update when a player disconnects that saves their data, with this as an example:
Code: Select all
try
{
// Save player data
dbManager.executeUpdate("UPDATE players SET save_data=? WHERE username=?", data);
}
catch (SQLException ex)
{
// Database write failed
trace(ex.getMessage()+ ", error saving data for "+user.getName());
}
However, my worry is what happens if there's a database error or the connection is lost, which can happen. The catch block will output the error, but then all of the user's session data disappears.
Is there a standard way of re-attempting the save the credentials until successful or should I just let it fail? Some ideas that came to mind are running a timer or using a thread.sleep() in a loop, but I don't know how practical or safe that would be, plus handling it happening for thousands of players if the database went down.
I hate the idea of a users data not saving and them losing progress.