So I am getting this error when by server first starts and everyone logs in at the same exact time.
This only happens when the server first turns on that it is fine. I have mysql loading and saving of my characters in my server and this is the problem.
Code:
Operation not allowed after ResultSet closed
I know what it means. Which is the server is trying to send the same result set again.
The error points to line 101 which is in this code:
Code:
public int loadGame(Client p, String playerName, String playerPass) {
int id = 0;
String stf = "";
String[] stuff = null;
//Misc.println("Got into mysql!");
try {
PreparedStatement ps = connect.prepareStatement("SELECT * FROM `users` WHERE username = '" + playerName + "'");
ResultSet load1 = ps.executeQuery();
String pass = null;
while (load1.next()) { <----- LINE 101!
id = load1.getInt("id");
pass = load1.getString("password");
p.playerRights = load1.getInt("rights");
}
if (id == 0) {
//Misc.println("User DNE");
p.registered = false;
return 0;
}
if (pass.equalsIgnoreCase(playerPass) == false) {
//Misc.println("User Wrong Password");
return 3;
}
p.registered = true;
//Misc.println("Right pass and exists");
//Misc.println("Got Rights");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `userPos` WHERE id = '" + id + "'");
while (load.next()) {
if (load.getInt("absX") == -1 || load.getInt("absY") == -1) {
p.heightLevel = 0;
p.teleportToX = Config.RESPAWN_X;
p.teleportToY = Config.RESPAWN_Y;
} else {
p.heightLevel = load.getInt("height");
p.teleportToX = load.getInt("absX");
p.teleportToY = load.getInt("absY");
}
}
//Misc.println("Got Pos");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `userInfo` WHERE id = '" + id + "'");
while (load.next()) {
p.crystalBowArrowCount = load.getInt("crystal-bow-shots");
p.skullTimer = load.getInt("skull-timer");
p.earningPotential = load.getInt("EP");
p.playerMagicBook = load.getInt("magic-book");
p.xpLock = load.getBoolean("xpLock");
p.Jail = load.getBoolean("xpLock");
p.Agrith = load.getBoolean("Agrith");
p.degradeTime = load.getInt("vls-hits");
p.Flambeed = load.getBoolean("Flambeed");
p.Karamel = load.getBoolean("Karamel");
p.Dessourt = load.getBoolean("Dessourt");
p.Culin = load.getBoolean("culin");
p.monkeyk0ed = load.getInt("Monkey-Kc");
p.specAmount = load.getDouble("special-amount");
p.altarPrayed = load.getInt("Altar");
}
//Misc.println("Got Info");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `barrowsNpcs` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("bNpcs");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
int i = 0;
for (String lol : stuff) {
p.barrowsNpcs[i][1] = Integer.parseInt(lol);
i++;
}
}
//Misc.println("Got barrows");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `moreInfo` WHERE id = '" + id + "'");
while (load.next()) {
p.randomCoffin = load.getInt("selected-coffin");
p.barrowsKillCount = load.getInt("barrows-killcount");
p.teleBlockDelay = System.currentTimeMillis();
p.teleBlockLength = load.getBigDecimal("teleblock-length").intValue();
p.pcPoints = load.getInt("pc-points");
p.gwdelay = load.getInt("gwdelay");
p.Arma = load.getInt("Arma-KC");
p.Band = load.getInt("Band-KC");
p.Zammy = load.getInt("Zammy-KC");
p.Sara = load.getInt("Sara-KC");
p.pkPoints = load.getInt("pk-points");
p.slayerTask = load.getInt("slayerTask");
p.taskAmount = load.getInt("taskAmount");
p.magePoints = load.getInt("magePoints");
p.autoRet = load.getInt("autoRet");
p.trade11 = load.getInt("trade11");
p.SpecialDelay = load.getInt("SpeDelay");
p.accountFlagged = load.getBoolean("flagged");
p.waveId = load.getInt("wave");
p.fightMode = load.getInt("fightMode");
}
//Misc.println("Got More Info");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `equip` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("equipment");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
for (String lol : stuff) {
String[] s = lol.split(",");
p.playerEquipment[Integer.parseInt(s[0])] = Integer.parseInt(s[1]);
p.playerEquipmentN[Integer.parseInt(s[0])] = Integer.parseInt(s[2]);
}
}
//Misc.println("Got EQUIP");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `look` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("looks");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
int i = 0;
for (String lol : stuff) {
p.playerAppearance[i] = Integer.parseInt(lol);
i++;
}
}
//Misc.println("Got Look");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
String skillz = "";
ResultSet load = query("SELECT * FROM `skill` WHERE id = '" + id + "'");
while (load.next()) {
skillz = load.getString("skills");
}
if (skillz.length() != 0) {
String[] Skills = skillz.split(" ");
//Misc.println(Skills[0] + " " + Skills[1]);
for (String lol : Skills) {
String[] s = lol.split(",");
p.playerLevel[Integer.parseInt(s[0])] = Integer.parseInt(s[1]);
p.playerXP[Integer.parseInt(s[0])] = Integer.parseInt(s[2]);
}
}
//Misc.println("Got skills");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `items` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("stuff");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
for (String lol : stuff) {
String[] s = lol.split(",");
p.playerItems[Integer.parseInt(s[0])] = Integer.parseInt(s[1]);
p.playerItemsN[Integer.parseInt(s[0])] = Integer.parseInt(s[2]);
}
}
//Misc.println("Got items");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `items` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("bank");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
for (String lol : stuff) {
String[] s = lol.split(",");
p.bankItems[Integer.parseInt(s[0])] = Integer.parseInt(s[1]);
p.bankItemsN[Integer.parseInt(s[0])] = Integer.parseInt(s[2]);
}
}
//Misc.println("Got bank");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ResultSet load = query("SELECT * FROM `friends` WHERE id = '" + id + "'");
while (load.next()) {
stf = load.getString("friendl");
}
if (stf.length() != 0) {
stuff = stf.split(" ");
for (String lol : stuff) {
String[] s = lol.split(",");
p.friends[Integer.parseInt(s[0])] = Long.parseLong(s[1]);
}
}
//Misc.println("Got friends");
} catch (SQLException ex) {
Logger.getLogger(SimpleMySQLManager.class.getName()).log(Level.SEVERE, null, ex);
}
//Misc.println("Done");
return 2;
}
Does anyone have any clue on how to fix this error? I tried googling it but everything I found could not be applied to this since a rsps is multiplayer.
So this is what is happening if you still don't understand. The server is sending this to the mysql
Code:
PreparedStatement ps = connect.prepareStatement("SELECT * FROM `users` WHERE username = '" + playerName + "'");
ResultSet load1 = ps.executeQuery();
and it is being sent all at once with a ton of player names.
Each new result set that is open the previous one is closed which messes up the player loading giving the error.