Jump to content

Recommended Posts

Posted

Just a suggestion, use try with resources for database interactions:

 

private void load()
{
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
Statement statement = con.createStatement();
ResultSet rset = statement.executeQuery("SELECT * FROM rank_pvp_system"))
{
 
With this, you don't need to close the resources after the usage, like con.close();
Posted (edited)

Just a suggestion, use try with resources for database interactions:

 

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

 
With this, you don't need to close the resources after the usage, like con.close();

 

 

Thanks to java 7 :D

Edited by SweeTs
Posted

BTW

 

any awesome solution for neasted try statements for example in here?

try(Connection con = L2DatabaseFactory.getInstance().getConnection())
{
	try(PreparedStatement statement = con.prepareStatement(QUERY_ONE))
	{
		try(ResultSet rset = statement.executeQuery())
		{
			something(rset);
		}
	}
	try(PreparedStatement statement = con.prepareStatement(QUERY_TWO))
	{
		statement.executeUpdate();
	}
}
catch(SQLException e)
{
	_log.error(e);
}
Posted (edited)

Maybe something like this:

try (Connection con = L2DatabaseFactory.getInstance().getConnection())
{
	statement = con.createStatement();

	statement.addBatch(insert1);
	statement.addBatch(insert2);
	
	statement.addBatch(update1);
	statement.addBatch(update2);
	statement.addBatch(update3);
	
	statement.addBatch(delete1);
	statement.addBatch(delete2);

	statement.batchExecute();
	
	
	statement = con.prepareStatement(select1);
	ResultSet rset = statement.executeQuery();
	
	something(rset);
}
catch (SQLException e)
{
	_log.error(e);
}
Edited by << Masterio >>
Posted

 

Maybe something like this:

try (Connection con = L2DatabaseFactory.getInstance().getConnection())
{
	statement = con.createStatement();

	statement.addBatch(insert1);
	statement.addBatch(insert2);
	
	statement.addBatch(update1);
	statement.addBatch(update2);
	statement.addBatch(update3);
	
	statement.addBatch(delete1);
	statement.addBatch(delete2);

	statement.batchExecute();
	
	
	statement = con.prepareStatement(select1);
	ResultSet rset = statement.executeQuery();
	
	something(rset);
}
catch (SQLException e)
{
	_log.error(e);
}

 

If you will get exception, memory will leak because of unclosed Statement and ResultSet. Only object that is safe is con

Posted (edited)

 I got this error:

 

 

Exception in thread "Thread-233" Exception in thread "Thread-232" java.lang.NullPointerException
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.KillerPvpStats.updateDailyStats(KillerPvpStats.java:274)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.PvpTable.getKillerPvpStats(PvpTable.java:229)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RankPvpSystem.doPvp(RankPvpSystem.java:64)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RankPvpSystemPc$RankPvpSystemPvpTask.run(RankPvpSystemPc.java:43)
    at java.lang.Thread.run(Unknown Source)

 

 and

 

sent bad RequestBypassToServer: "RPS.RPC:1"
java.lang.NullPointerException
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RPCTable.getRpcByPlayerId(RPCTable.java:91)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RankPvpSystemRPC.playerResponseHtm(RankPvpSystemRPC.java:25)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RankPvpSystemRPC.sendPlayerResponse(RankPvpSystemRPC.java:17)
    at com.l2jserver.gameserver.masteriopack.rankpvpsystem.RankPvpSystemBypass.executeCommand(RankPvpSystemBypass.java:75)
    at com.l2jserver.gameserver.network.clientpackets.RequestBypassToServer.runImpl(RequestBypassToServer.java:287)
    at com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:62)
    at com.l2jserver.gameserver.network.L2GameClient.run(L2GameClient.java:1101)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Edited by Amida Nguyen
Guest
This topic is now closed to further replies.



×
×
  • Create New...