Always get this error when trying to gather data from MySQL after a period of time:
code:
public class DatabaseManager {
private SqlService sqlService;
private Connection connection;
private PreparedStatement statement;
public DatabaseManager(){
this.createTable();
}
public DataSource getDatasource() throws SQLException {
if (sqlService == null){
sqlService = Sponge.getServiceManager().provideUnchecked(SqlService.class);
}
DataSource dataSource = sqlService.getDataSource(Main.INSTANCE.getConfigManger().getDatabaseString());
return dataSource;
}
public void savePart(EntityPlayerMP playerMP, NBTTagCompound tagCompound){
try {
String sql = String.format("update pixelmonsync set party = '%s' where uuid = '%s'", tagCompound.toString(), playerMP.getUniqueID().toString());
System.out.println(playerMP.getUniqueID().toString());
connection = getDatasource().getConnection();
statement = connection.prepareStatement(sql);
statement.execute();
}catch (SQLException e){
e.printStackTrace();
}finally {
close();
}
}
//same operations.....
private void close() {
try {
if (connection!=null){
connection.close();
connection = null;
}
if (statement!=null) {
statement.close();
statement = null;
}
}catch (SQLException e){
e.printStackTrace();
}
}