java 运行如下查寻15次,程序就当,求死。。
java 运行如下查寻15次,程序就当,而且每次都是运行15次之后,程序就没反应了,哪位大哥救我一下。
public void ZZ(L1PcInstance pc,int money) {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
int Point =0;
pc.getQuest().set_step(10000, 0);
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("select * from user_register where name=?");
pstm.setString(1, pc.getName());
rs = pstm.executeQuery();
if (rs.next()) {
if(money+rs.getInt("event_point")<2000000000){
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("UPDATE user_register SET event_point=event_point+? WHERE name =?");
pstm.setInt(1, money);
pstm.setString(2, pc.getName());
pstm.execute();
} catch (
SQLException e) {
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
pc.sendPackets(new S_SystemMessage("您已成功向交易中心转账:"+money));
}
}else{
try {
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("select password from accounts where login=?");
pstm.setString(1, pc.getAccountName());
rs = pstm.executeQuery();
if(rs.next()){
pstm = con
.prepareStatement("INSERT INTO user_register SET name = ?, e_pass = ?, event_point = ?");
pstm.setString(1, pc.getName());
pstm.setString(2, rs.getString("password"));
pstm.setInt(3, money);
pstm.execute();
pc.sendPackets(new S_SystemMessage("您已成功开通离线交易,并转账:"+money));
}
} catch (SQLException e){
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
SQLUtil.close(pstm);
SQLUtil.close(con);
SQLUtil.close(rs);
} catch(SQLException e){
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
------解决方案--------------------finally里面关闭连接
------解决方案--------------------
try{..}
catch(Exception e)(..)
finally(
if(rs != null)rs.close();
if(pstm != null)pstm.close();
if(con != null)con.close();
)
------解决方案--------------------数据库连接没关闭,如果你设置数据库最大连接数为100,就是运行100次,当掉。