public void deleteCharacter(String accountName, String charName) throws Exception {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("SELECT * FROM characters WHERE account_name=? AND char_name=?");
pstm.setString(1, accountName);
pstm.setString(2, charName);
rs = pstm.executeQuery();
if (!rs.next()) {
_log.warning("invalid delete char request: account=" + accountName + " char=" + charName);
throw new RuntimeException("could not delete character");
}
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("SELECT * FROM characters WHERE account_name=? AND char_name=?");
pstm.setString(1, accountName);
pstm.setString(2, charName);
rs = pstm.executeQuery();
if (!rs.next()) {
_log.warning("invalid delete char request: account=" + accountName + " char=" + charName);
throw new RuntimeException("could not delete character");
}
pstm = con.prepareStatement("DELETE FROM character_1 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_2 WHERE char_obj_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_3 WHERE object_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_4 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_5 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_6 WHERE char_obj_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_7 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_8 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM characters WHERE char_name=?");
pstm.setString(1, charName);
pstm.execute();
} catch (SQLException e) {
throw e;
} finally {
SQLUtil.close(rs);
SQLUtil.close(pstm);
SQLUtil.close(con);
}
}
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_2 WHERE char_obj_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_3 WHERE object_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_4 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_5 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_6 WHERE char_obj_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_7 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM character_8 WHERE char_id IN (SELECT objid FROM characters WHERE char_name = ?)");
pstm.setString(1, charName);
pstm.execute();
pstm = con.prepareStatement("DELETE FROM characters WHERE char_name=?");
pstm.setString(1, charName);
pstm.execute();
} catch (SQLException e) {
throw e;
} finally {
SQLUtil.close(rs);
SQLUtil.close(pstm);
SQLUtil.close(con);
}
}
안녕하세요 sql 초보입니다..
위의 쿼리문에서 메모리 누수가 있는거같습니다..
이것저것 찾아보면서 혼자 해결해보려고했지만
도저희 답이 안나와서 고수분들께 질문드립니다..
혹시 위의 쿼리문에서 잘못된곳이 있다면 짧게나마 고수분들의 조언좀 부탁드리겠습니다 꾸벅