wibox Posted December 14, 2012 Posted December 14, 2012 code: public int getLastGotKill() { Connection con = null; int last_pvp_time = 0; try { con = L2DatabaseFactory.getInstance().getConnection(false); PreparedStatement statement; statement = con.prepareStatement("select last_got_kill from characters where obj_Id=?"); statement.setInt(1, getObjectId()); ResultSet rset = statement.executeQuery(); while(rset.next()) { last_pvp_time = rset.getInt("last_got_kill"); _log.info("last pvp time is : " + last_pvp_time); } rset.close(); rset = null; statement.close(); statement = null; } catch(Exception e) { if(Config.ENABLE_ALL_EXCEPTIONS) e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } return last_pvp_time; } why does this return always 0 ? i am sure that the column last_got_kill is not zero for the selected player
0 Tryskell Posted December 14, 2012 Posted December 14, 2012 Bhe my bad,you used other name for initial variable. Cleaned version is (java 7) public int getLastGotKill() { int lastGotKill = 0; try (Connection con = L2DatabaseFactory.getInstance().getConnection(false)) { PreparedStatement statement = con.prepareStatement("SELECT last_got_kill FROM characters WHERE obj_Id=?"); statement.setInt(1, getObjectId()); ResultSet rset = statement.executeQuery(); while(rset.next()) { lastGotKill = rset.getInt("last_got_kill"); _log.info("lastGotKill is : " + lastGotKill); } rset.close(); statement.close(); } catch(Exception e) { if(Config.ENABLE_ALL_EXCEPTIONS) e.printStackTrace(); } return lastGotKill; } About your problem, do you see the log.info while executing that method ? Are you SO SURE about the variable being different of 0 ? If you edited at hand you have to save the change or if you used a query to save it, the query has to be correct. Are you sure you use getLastGotKill() on the good instance ? (killed != killer). Are you sure last_got_kill (on your sql) is an int type ?
0 wibox Posted December 14, 2012 Author Posted December 14, 2012 so i fixed it by changing getInt() to getLong() and last_got_kill variable type from int to long.
Question
wibox
code:
public int getLastGotKill() { Connection con = null; int last_pvp_time = 0; try { con = L2DatabaseFactory.getInstance().getConnection(false); PreparedStatement statement; statement = con.prepareStatement("select last_got_kill from characters where obj_Id=?"); statement.setInt(1, getObjectId()); ResultSet rset = statement.executeQuery(); while(rset.next()) { last_pvp_time = rset.getInt("last_got_kill"); _log.info("last pvp time is : " + last_pvp_time); } rset.close(); rset = null; statement.close(); statement = null; } catch(Exception e) { if(Config.ENABLE_ALL_EXCEPTIONS) e.printStackTrace(); } finally { CloseUtil.close(con); con = null; } return last_pvp_time; }why does this return always 0 ? i am sure that the column last_got_kill is not zero for the selected player
2 answers to this question
Recommended Posts