Experimental DB pool + fixed stat overflow on equips

Implemented EXPERIMENTAL DBCP (connection pool), trying to improve
concorrent access to DB. Added door portals on Kerning Square. Fixed
equipments getting stat overflow when upgrading stats. Fixed expiring
pets crashing the client in some cases.
This commit is contained in:
ronancpl
2017-08-23 18:01:17 -03:00
parent 36db21bf80
commit 6628e3db54
190 changed files with 18265 additions and 2183 deletions
+6 -2
View File
@@ -23,6 +23,7 @@ package client;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Deque;
@@ -109,7 +110,9 @@ public class BuddyList {
public void loadFromDb(int characterId) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT b.buddyid, b.pending, b.group, c.name as buddyname FROM buddies as b, characters as c WHERE c.id = b.buddyid AND b.characterid = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT b.buddyid, b.pending, b.group, c.name as buddyname FROM buddies as b, characters as c WHERE c.id = b.buddyid AND b.characterid = ?");
ps.setInt(1, characterId);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
@@ -121,10 +124,11 @@ public class BuddyList {
}
rs.close();
ps.close();
ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM buddies WHERE pending = 1 AND characterid = ?");
ps = con.prepareStatement("DELETE FROM buddies WHERE pending = 1 AND characterid = ?");
ps.setInt(1, characterId);
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
+107 -45
View File
@@ -622,7 +622,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
ps.setInt(2, accountid);
ps.executeUpdate();
}
} catch (Exception e) {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -630,9 +631,11 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public static boolean ban(String id, String reason, boolean accountId) {
PreparedStatement ps = null;
ResultSet rs = null;
ResultSet rs = null;
Connection con = null;
try {
Connection con = DatabaseConnection.getConnection();
con = DatabaseConnection.getConnection();
if (id.matches("/[0-9]{1,3}\\..*")) {
ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
ps.setString(1, id);
@@ -649,16 +652,22 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
boolean ret = false;
ps.setString(1, id);
rs = ps.executeQuery();
if (rs.next()) {
try (PreparedStatement psb = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
psb.setString(1, reason);
psb.setInt(2, rs.getInt(1));
psb.executeUpdate();
}
ret = true;
if (rs.next()) {
Connection con2 = DatabaseConnection.getConnection();
try (PreparedStatement psb = con2.prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
psb.setString(1, reason);
psb.setInt(2, rs.getInt(1));
psb.executeUpdate();
} finally {
con2.close();
}
ret = true;
}
rs.close();
rs.close();
ps.close();
con.close();
return ret;
} catch (SQLException ex) {
ex.printStackTrace();
@@ -670,6 +679,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1395,6 +1407,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
ps.setInt(1, skill.getId());
ps.setInt(2, id);
ps.execute();
} finally {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
@@ -1464,10 +1478,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
if (id / 1000000 == 2) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.isConsumeOnPickup(id)) {
if (ii.isPartyItem(id)) {
if (ItemConstants.isPartyItem(id)) {
List<MapleCharacter> pchr = c.getPlayer().getPartyMembersOnSameMap();
if(!ii.isPartyAllcure(id)) {
if(!ItemConstants.isPartyAllcure(id)) {
if(!pchr.isEmpty()) {
for (MapleCharacter mc : pchr) {
ii.getItemEffect(id).applyTo(mc);
@@ -1663,6 +1677,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
try (PreparedStatement ps = con.prepareStatement("DELETE FROM guilds WHERE guildid = ?")) {
ps.setInt(1, id);
ps.execute();
} finally {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
@@ -1697,8 +1713,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public static boolean deleteCharFromDB(MapleCharacter player) {
int cid = player.getId(), accId = -1, world = 0;
Connection con = DatabaseConnection.getConnection();
Connection con = null;
try {
con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT accountid, world FROM characters WHERE id = ?")) {
ps.setInt(1, cid);
@@ -2297,7 +2315,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
expiretask = TimerManager.getInstance().register(new Runnable() {
@Override
public void run() {
MapleItemInformationProvider miip = MapleItemInformationProvider.getInstance();
boolean deletedCoupon = false;
long expiration, currenttime = System.currentTimeMillis();
@@ -2323,12 +2340,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
} else if (expiration != -1 && expiration < currenttime) {
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
toberemove.add(item);
if(miip.isRateCoupon(item.getItemId())) {
if(ItemConstants.isRateCoupon(item.getItemId())) {
deletedCoupon = true;
}
}
}
for (Item item : toberemove) {
if(item.getPetId() > -1) unequipPet(getPet(getPetIndex(item.getPetId())), true);
MapleInventoryManipulator.removeFromSlot(client, inv.getType(), item.getPosition(), item.getQuantity(), true);
}
toberemove.clear();
@@ -2532,7 +2550,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
Map<String, String> character = new LinkedHashMap<>();
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `id`, `accountid`, `name` FROM `characters` WHERE `name` = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT `id`, `accountid`, `name` FROM `characters` WHERE `name` = ?")) {
ps.setString(1, name);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
@@ -2545,6 +2565,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
character.put(rs.getMetaData().getColumnLabel(i), rs.getString(i));
}
}
} finally {
con.close();
}
} catch (SQLException sqle) {
sqle.printStackTrace();
@@ -2855,7 +2877,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public static int getAccountIdByName(String name) {
try {
int id;
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
ps.setString(1, name);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
@@ -2865,6 +2889,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
id = rs.getInt("accountid");
}
} finally {
con.close();
}
return id;
} catch (Exception e) {
@@ -2876,7 +2902,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public static int getIdByName(String name) {
try {
int id;
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT id FROM characters WHERE name = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT id FROM characters WHERE name = ?")) {
ps.setString(1, name);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
@@ -2886,6 +2913,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
id = rs.getInt("id");
}
} finally {
con.close();
}
return id;
} catch (Exception e) {
@@ -2897,7 +2926,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public static String getNameById(int id) {
try {
String name;
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM characters WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT name FROM characters WHERE id = ?")) {
ps.setInt(1, id);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
@@ -2907,6 +2937,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
name = rs.getString("name");
}
} finally {
con.close();
}
return name;
} catch (Exception e) {
@@ -3715,11 +3747,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
lastfametime = System.currentTimeMillis();
lastmonthfameids.add(Integer.valueOf(to.getId()));
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO famelog (characterid, characterid_to) VALUES (?, ?)")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO famelog (characterid, characterid_to) VALUES (?, ?)")) {
ps.setInt(1, getId());
ps.setInt(2, to.getId());
ps.executeUpdate();
}
finally {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -3794,7 +3830,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
public boolean isBeginnerJob() {
return (getJob().getId() == 0 || getJob().getId() == 1000 || getJob().getId() == 2000) && getLevel() < 11;
return (getJob().getId() == 0 || getJob().getId() == 1000 || getJob().getId() == 2000);
}
public boolean isGM() {
@@ -3832,7 +3868,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
int improvingMaxHPLevel = 0;
int improvingMaxMPLevel = 0;
if (isBeginnerJob()) {
if (isBeginnerJob() && getLevel() < 11) {
remainingAp = 0;
if (getLevel() < 6) {
str += 5;
@@ -3904,9 +3940,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
if (level == 200) {
exp.set(0);
}
hp = maxhp;
mp = maxmp;
recalcLocalStats();
hp = localmaxhp;
mp = localmaxmp;
List<Pair<MapleStat, Integer>> statup = new ArrayList<>(10);
statup.add(new Pair<>(MapleStat.AVAILABLEAP, remainingAp));
statup.add(new Pair<>(MapleStat.HP, localmaxhp));
@@ -4116,10 +4152,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
dropCoupon = 1;
}
private boolean isExpCoupon(int couponId) {
return couponId / 1000 == 5211;
}
private int getCouponMultiplier(int couponId) {
return activeCouponRates.get(couponId);
}
@@ -4152,7 +4184,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
int couponQty = coupon.getValue();
commitBuffCoupon(couponId);
if(isExpCoupon(couponId)) setExpCouponRate(couponId, couponQty);
if(ItemConstants.isExpCoupon(couponId)) setExpCouponRate(couponId, couponQty);
else setDropCouponRate(couponId, couponQty);
}
}
@@ -4162,7 +4194,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
for(Entry<Integer,Integer> coupon: activeCoupons.entrySet()) {
int couponId = coupon.getKey();
if(isExpCoupon(couponId)) {
if(ItemConstants.isExpCoupon(couponId)) {
if(maxExpRate < getCouponMultiplier(couponId)) {
maxExpCouponId = couponId;
maxExpRate = getCouponMultiplier(couponId);
@@ -4199,7 +4231,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
List<Integer> active = Server.getInstance().getActiveCoupons();
for(Item it: this.getInventory(MapleInventoryType.CASH).list()) {
if(MapleItemInformationProvider.getInstance().isRateCoupon(it.getItemId()) && active.contains(it.getItemId())) {
if(ItemConstants.isRateCoupon(it.getItemId()) && active.contains(it.getItemId())) {
Integer count = activeCoupons.get(it.getItemId());
if(count != null) activeCoupons.put(it.getItemId(), count + 1);
@@ -4231,10 +4263,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
chrLock.unlock();
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
for (MapleBuffStatValueHolder mbsvh : allBuffs) {
if (ii.isRateCoupon(mbsvh.effect.getSourceId())) {
if (ItemConstants.isRateCoupon(mbsvh.effect.getSourceId())) {
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
}
@@ -4249,6 +4279,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
MapleCharacter ret = new MapleCharacter();
ret.client = client;
ret.id = charid;
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
ps.setInt(1, charid);
@@ -4570,6 +4601,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
ret.maplemount.setTiredness(mounttiredness);
ret.maplemount.setActive(false);
con.close();
return ret;
} catch (SQLException | RuntimeException e) {
e.printStackTrace();
@@ -4723,6 +4755,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
ps.close();
rs.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -5183,6 +5216,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
ps.executeBatch();
}
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
@@ -5191,13 +5226,16 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void saveGuildStatus() {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET guildid = ?, guildrank = ?, allianceRank = ? WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = ?, guildrank = ?, allianceRank = ? WHERE id = ?")) {
ps.setInt(1, guildid);
ps.setInt(2, guildRank);
ps.setInt(3, allianceRank);
ps.setInt(4, id);
ps.executeUpdate();
}
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
@@ -5209,13 +5247,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
public final boolean insertNewChar() {
final Connection con = DatabaseConnection.getConnection();
Connection con = null;
PreparedStatement ps = null;
try {
con = DatabaseConnection.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", DatabaseConnection.RETURN_GENERATED_KEYS);
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, 12);
ps.setInt(2, 5);
ps.setInt(3, 4);
@@ -5303,6 +5343,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
con.setAutoCommit(true);
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -5313,8 +5354,9 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public synchronized void saveToDB() {
Calendar c = Calendar.getInstance();
FilePrinter.print(FilePrinter.SAVING_CHARACTER, "Attempting to save " + name + " at " + c.getTime().toString());
Connection con = DatabaseConnection.getConnection();
Connection con = null;
try {
con = DatabaseConnection.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
PreparedStatement ps;
@@ -5585,6 +5627,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
try {
con.setAutoCommit(true);
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
con.close();
} catch (Exception e) {
e.printStackTrace();
}
@@ -5632,13 +5675,16 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
public void sendNote(String to, String msg, byte fame) throws SQLException {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
ps.setString(1, to);
ps.setString(2, this.getName());
ps.setString(3, msg);
ps.setLong(4, System.currentTimeMillis());
ps.setByte(5, fame);
ps.executeUpdate();
} finally {
con.close();
}
}
@@ -5759,11 +5805,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void setHasMerchant(boolean set) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET HasMerchant = ? WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = ? WHERE id = ?")) {
ps.setInt(1, set ? 1 : 0);
ps.setInt(2, id);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -5772,11 +5822,14 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void addMerchantMesos(int add) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, merchantmeso + add);
ps.setInt(2, id);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
return;
@@ -5786,11 +5839,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void setMerchantMeso(int set) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, set);
ps.setInt(2, id);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
return;
@@ -5969,11 +6024,13 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void changeName(String name) {
this.name = name;
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE `characters` SET `name` = ? WHERE `id` = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `name` = ? WHERE `id` = ?");
ps.setString(1, name);
ps.setInt(2, id);
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -6157,7 +6214,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
public void showNote() {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM notes WHERE `to`=? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM notes WHERE `to`=? AND `deleted` = 0", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
ps.setString(1, this.getName());
try (ResultSet rs = ps.executeQuery()) {
rs.last();
@@ -6166,6 +6224,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
client.announce(MaplePacketCreator.showNotes(rs, count));
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -6522,6 +6582,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
ps.setInt(3, reason);
ps.setInt(4, accountid);
ps.executeUpdate();
} finally {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
+108 -30
View File
@@ -180,7 +180,8 @@ public class MapleClient {
PreparedStatement ps;
List<CharNameAndId> chars = new ArrayList<>(15);
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?");
Connection con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?");
ps.setInt(1, this.getAccID());
ps.setInt(2, serverId);
try (ResultSet rs = ps.executeQuery()) {
@@ -189,6 +190,7 @@ public class MapleClient {
}
}
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -202,7 +204,8 @@ public class MapleClient {
public boolean hasBannedIP() {
boolean ret = false;
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
ps.setString(1, session.getRemoteAddress().toString());
try (ResultSet rs = ps.executeQuery()) {
rs.next();
@@ -211,6 +214,7 @@ public class MapleClient {
}
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -222,7 +226,8 @@ public class MapleClient {
return voteTime;
}
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
ps.setString(1, accountName);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
@@ -231,6 +236,7 @@ public class MapleClient {
voteTime = rs.getInt("date");
}
}
con.close();
} catch (SQLException e) {
FilePrinter.printError("hasVotedAlready.txt", e);
return -1;
@@ -255,8 +261,10 @@ public class MapleClient {
boolean ret = false;
PreparedStatement ps = null;
Connection con = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?");
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?");
ps.setString(1, hwid);
ResultSet rs = ps.executeQuery();
if(rs != null && rs.next()) {
@@ -270,6 +278,10 @@ public class MapleClient {
if(ps != null && !ps.isClosed()) {
ps.close();
}
if(con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e){
e.printStackTrace();
}
@@ -293,7 +305,9 @@ public class MapleClient {
}
}
sql.append(")");
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement(sql.toString())) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement(sql.toString())) {
i = 0;
for (String mac : macs) {
i++;
@@ -305,7 +319,9 @@ public class MapleClient {
ret = true;
}
}
}
} finally {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
@@ -314,21 +330,25 @@ public class MapleClient {
private void loadHWIDIfNescessary() throws SQLException {
if(hwid == null) {
try(PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try(PreparedStatement ps = con.prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
ps.setInt(1, accId);
try(ResultSet rs = ps.executeQuery()) {
if(rs.next()) {
hwid = rs.getString("hwid");
}
}
}
} finally {
con.close();
}
}
}
// TODO: Recode to close statements...
private void loadMacsIfNescessary() throws SQLException {
if (macs.isEmpty()) {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
ps.setInt(1, accId);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
@@ -339,15 +359,19 @@ public class MapleClient {
}
}
}
}
} finally {
con.close();
}
}
}
public void banHWID() {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
Connection con = null;
try {
loadHWIDIfNescessary();
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)");
ps.setString(1, hwid);
ps.executeUpdate();
@@ -355,8 +379,12 @@ public class MapleClient {
e.printStackTrace();
} finally {
try {
if(ps != null && !ps.isClosed())
if(ps != null && !ps.isClosed()) {
ps.close();
}
if(con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -364,9 +392,11 @@ public class MapleClient {
}
public void banMacs() {
Connection con = DatabaseConnection.getConnection();
Connection con = null;
try {
loadMacsIfNescessary();
con = DatabaseConnection.getConnection();
List<String> filtered = new LinkedList<>();
try (PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters"); ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
@@ -389,6 +419,8 @@ public class MapleClient {
}
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -408,11 +440,14 @@ public class MapleClient {
public void setPin(String pin) {
this.pin = pin;
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
ps.setString(1, pin);
ps.setInt(2, accId);
ps.executeUpdate();
}
} finally {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -437,11 +472,14 @@ public class MapleClient {
public void setPic(String pic) {
this.pic = pic;
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
ps.setString(1, pic);
ps.setInt(2, accId);
ps.executeUpdate();
}
} finally {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -471,10 +509,11 @@ public class MapleClient {
getSession().close(true);
}
int loginok = 5;
Connection con = DatabaseConnection.getConnection();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT id, password, salt, gender, banned, gm, pin, pic, characterslots, tos FROM accounts WHERE name = ?");
ps.setString(1, login);
rs = ps.executeQuery();
@@ -522,6 +561,9 @@ public class MapleClient {
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -533,11 +575,12 @@ public class MapleClient {
}
public Calendar getTempBanCalendar() {
Connection con = DatabaseConnection.getConnection();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
final Calendar lTempban = Calendar.getInstance();
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
ps.setInt(1, getAccID());
rs = ps.executeQuery();
@@ -560,6 +603,9 @@ public class MapleClient {
if (rs != null) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -595,8 +641,10 @@ public class MapleClient {
this.hwid = hwid.toString();
PreparedStatement ps = null;
Connection con = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?");
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?");
ps.setString(1, this.hwid);
ps.setInt(2, accId);
ps.executeUpdate();
@@ -608,6 +656,9 @@ public class MapleClient {
if(ps != null && !ps.isClosed()) {
ps.close();
}
if(con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -629,8 +680,10 @@ public class MapleClient {
newMacData.append(", ");
}
}
Connection con = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
ps.setString(1, newMacData.toString());
ps.setInt(2, accId);
ps.executeUpdate();
@@ -642,8 +695,11 @@ public class MapleClient {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
ex.printStackTrace();
}
}
}
@@ -664,6 +720,8 @@ public class MapleClient {
ps.setInt(2, getAccID());
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -714,6 +772,8 @@ public class MapleClient {
} else {
loggedIn = false;
}
con.close();
return state;
} catch (SQLException e) {
loggedIn = false;
@@ -1006,7 +1066,8 @@ public class MapleClient {
return true;
}
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
ps.setInt(1, accId);
ResultSet rs = ps.executeQuery();
@@ -1017,10 +1078,11 @@ public class MapleClient {
}
ps.close();
rs.close();
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
ps = con.prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
ps.setInt(1, accId);
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1030,7 +1092,8 @@ public class MapleClient {
public int getVotePoints(){
int points = 0;
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `votes` FROM accounts WHERE id = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT `votes` FROM accounts WHERE id = ?");
ps.setInt(1, accId);
ResultSet rs = ps.executeQuery();
@@ -1040,6 +1103,7 @@ public class MapleClient {
ps.close();
rs.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1070,6 +1134,8 @@ public class MapleClient {
ps.setInt(2, accId);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1107,15 +1173,19 @@ public class MapleClient {
public boolean gainCharacterSlot() {
if (characterSlots < 15) {
Connection con = DatabaseConnection.getConnection();
Connection con = null;
try {
con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET characterslots = ? WHERE id = ?")) {
ps.setInt(1, this.characterSlots += 1);
ps.setInt(2, accId);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
}
return true;
}
@@ -1123,10 +1193,11 @@ public class MapleClient {
}
public final byte getGReason() {
final Connection con = DatabaseConnection.getConnection();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `greason` FROM `accounts` WHERE id = ?");
ps.setInt(1, accId);
rs = ps.executeQuery();
@@ -1143,8 +1214,11 @@ public class MapleClient {
if (rs != null) {
rs.close();
}
if (con != null) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
}
}
return 0;
@@ -1156,12 +1230,16 @@ public class MapleClient {
public void setGender(byte m) {
this.gender = m;
Connection con = null;
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
ps.setByte(1, gender);
ps.setInt(2, accId);
ps.executeUpdate();
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
+7 -2
View File
@@ -21,6 +21,7 @@
*/
package client;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -38,7 +39,8 @@ public class MapleFamily {
public MapleFamily(int cid) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT familyid FROM family_character WHERE cid = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT familyid FROM family_character WHERE cid = ?");
ps.setInt(1, cid);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
@@ -46,6 +48,7 @@ public class MapleFamily {
}
ps.close();
rs.close();
con.close();
getMapleFamily();
} catch (SQLException ex) {
ex.printStackTrace();
@@ -54,7 +57,8 @@ public class MapleFamily {
private static void getMapleFamily() {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM family_character WHERE familyid = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM family_character WHERE familyid = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
@@ -72,6 +76,7 @@ public class MapleFamily {
}
rs.close();
ps.close();
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
+3 -1
View File
@@ -51,7 +51,7 @@ public class MapleRing implements Comparable<MapleRing> {
public static MapleRing loadFromDb(int ringId) {
try {
MapleRing ret = null;
Connection con = DatabaseConnection.getConnection(); // Get a connection to the database
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM rings WHERE id = ?"); // Get ring details..
ps.setInt(1, ringId);
ResultSet rs = ps.executeQuery();
@@ -60,6 +60,7 @@ public class MapleRing implements Comparable<MapleRing> {
}
rs.close();
ps.close();
con.close();
return ret;
} catch (SQLException ex) {
ex.printStackTrace();
@@ -102,6 +103,7 @@ public class MapleRing implements Comparable<MapleRing> {
ps.setInt(2, ringID[0]);
ps.executeUpdate();
ps.close();
con.close();
return ringID[0];
} catch (SQLException ex) {
ex.printStackTrace();
+5 -1
View File
@@ -91,7 +91,8 @@ public final class MonsterBook {
}
public void loadCards(final int charid) throws SQLException {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT cardid, level FROM monsterbook WHERE charid = ? ORDER BY cardid ASC")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT cardid, level FROM monsterbook WHERE charid = ? ORDER BY cardid ASC")) {
ps.setInt(1, charid);
try (ResultSet rs = ps.executeQuery()) {
int cardid, level;
@@ -107,6 +108,8 @@ public final class MonsterBook {
}
}
}
con.close();
calculateLevel();
}
@@ -139,6 +142,7 @@ public final class MonsterBook {
ps = con.prepareStatement(query.toString());
ps.execute();
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
+14 -2
View File
@@ -450,7 +450,8 @@ public class Commands {
Pair<Integer, String> data = listIterator.next();
output += "#b" + data.getRight() + "#k is dropped by:\r\n";
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM drop_data WHERE itemid = ? LIMIT 50");
ps.setInt(1, data.getLeft());
ResultSet rs = ps.executeQuery();
while(rs.next()) {
@@ -461,6 +462,7 @@ public class Commands {
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
player.dropMessage("There was a problem retreiving the required data. Please try again.");
e.printStackTrace();
@@ -641,13 +643,16 @@ public class Commands {
case "ranks":
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
rs = ps.executeQuery();
player.announce(MaplePacketCreator.showPlayerRanks(9010000, rs));
ps.close();
rs.close();
con.close();
} catch(SQLException ex) {
ex.printStackTrace();
} finally {
@@ -658,6 +663,9 @@ public class Commands {
if(rs != null && !rs.isClosed()) {
rs.close();
}
if(con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1774,6 +1782,8 @@ public class Commands {
ps.executeUpdate();
ps.close();
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
c.getPlayer().message("Error occured while banning IP address");
@@ -1819,6 +1829,8 @@ public class Commands {
p = con.prepareStatement("DELETE FROM macbans WHERE aid = " + aid);
p.executeUpdate();
con.close();
} catch (Exception e) {
e.printStackTrace();
player.message("Failed to unban " + sub[1]);
+8 -4
View File
@@ -61,6 +61,7 @@ public enum ItemFactory {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = DatabaseConnection.getConnection();
try {
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM `inventoryitems` LEFT JOIN `inventoryequipment` USING(`inventoryitemid`) WHERE `type` = ? AND `");
@@ -70,8 +71,7 @@ public enum ItemFactory {
query.append(" AND `inventorytype` = ").append(MapleInventoryType.EQUIPPED.getType());
}
ps = DatabaseConnection.getConnection().prepareStatement(query.toString());
ps = con.prepareStatement(query.toString());
ps.setInt(1, value);
ps.setInt(2, id);
rs = ps.executeQuery();
@@ -120,13 +120,17 @@ public enum ItemFactory {
rs.close();
ps.close();
con.close();
} finally {
if (rs != null) {
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (ps != null) {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
}
return items;
}
+2 -2
View File
@@ -232,7 +232,7 @@ public class MapleInventory implements Iterable<Item> {
public void addSlot(short slot, Item item) {
inventory.put(slot, item);
if(MapleItemInformationProvider.getInstance().isRateCoupon(item.getItemId())) {
if(ItemConstants.isRateCoupon(item.getItemId())) {
owner.updateCouponRates();
}
}
@@ -240,7 +240,7 @@ public class MapleInventory implements Iterable<Item> {
public void removeSlot(short slot) {
Item item = inventory.remove(slot);
if(item != null && MapleItemInformationProvider.getInstance().isRateCoupon(item.getItemId())) {
if(item != null && ItemConstants.isRateCoupon(item.getItemId())) {
owner.updateCouponRates();
}
}
+15 -6
View File
@@ -34,6 +34,7 @@ import server.movement.AbsoluteLifeMovement;
import server.movement.LifeMovement;
import server.movement.LifeMovementFragment;
import client.MapleCharacter;
import java.sql.Connection;
import tools.MaplePacketCreator;
/**
@@ -60,7 +61,8 @@ public class MaplePet extends Item {
public static MaplePet loadFromDb(int itemid, short position, int petid) {
try {
MaplePet ret = new MaplePet(itemid, position, petid);
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name, level, closeness, fullness, summoned FROM pets WHERE petid = ?"); // Get pet details..
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT name, level, closeness, fullness, summoned FROM pets WHERE petid = ?"); // Get pet details..
ps.setInt(1, petid);
ResultSet rs = ps.executeQuery();
rs.next();
@@ -71,6 +73,7 @@ public class MaplePet extends Item {
ret.setSummoned(rs.getInt("summoned") == 1);
rs.close();
ps.close();
con.close();
return ret;
} catch (SQLException e) {
e.printStackTrace();
@@ -80,7 +83,8 @@ public class MaplePet extends Item {
public void saveToDb() {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ? WHERE petid = ?");
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ? WHERE petid = ?");
ps.setString(1, getName());
ps.setInt(2, getLevel());
ps.setInt(3, getCloseness());
@@ -89,6 +93,7 @@ public class MaplePet extends Item {
ps.setInt(6, getUniqueId());
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -96,7 +101,8 @@ public class MaplePet extends Item {
public static int createPet(int itemid) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
@@ -106,6 +112,7 @@ public class MaplePet extends Item {
}
rs.close();
ps.close();
con.close();
return ret;
} catch (SQLException e) {
e.printStackTrace();
@@ -115,7 +122,8 @@ public class MaplePet extends Item {
public static int createPet(int itemid, byte level, int closeness, int fullness) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
ps.setByte(2, level);
ps.setInt(3, closeness);
@@ -125,9 +133,10 @@ public class MaplePet extends Item {
int ret = -1;
if (rs.next()) {
ret = rs.getInt(1);
rs.close();
ps.close();
}
rs.close();
ps.close();
con.close();
return ret;
} catch (SQLException e) {
e.printStackTrace();