java执行存储过程会频繁锁表_Java调用存储过程,随着按钮点击增多,调用存储过程也增多,会出现超时问题...

刚开始代码是这样的直接通过jpa连接,刚开始点击调用存储过程的按钮,没啥问题,等点击多了就会没反应:日志报数据库连接超时:

public String execute(Entity entity) {

Session session = (Session) this.getJpa().getManager().getDelegate();

SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory();

Connection conn = null;

String result = null;

try {

conn = sessionFactory.getConnectionProvider().getConnection();

CallableStatement call = conn.prepareCall("{call SP_FORMER_BMP_INFO_AUDIT(?,?,?,?,?,?,?,?,?,?,?,?)}");

call.setString(1, entity.getParam1());

call.setString(2, entity.getParam2());

call.setString(3, entity.getParam3());

call.setString(4, entity.getParam4());

call.setString(5, entity.getParam5());

call.setString(6, entity.getParam6());

call.setString(7, entity.getParam7());

call.setString(8, entity.getParam8());

call.setString(9, entity.getParam9());

call.setString(10, entity.getParam10());

call.setString(11, entity.getParam11());

call.registerOutParameter(12, Types.VARCHAR);

call.execute();

result = call.getString(12);

System.out.println("参数:"+entity.getParam1()+";"+entity.getParam2()+";"+entity.getParam3()+";"

+entity.getParam4()+";"+entity.getParam5()+";"+entity.getParam6()+";"

+entity.getParam7()+":"+entity.getParam8()+";"+entity.getParam9()+";"

+entity.getParam10()+";"+entity.getParam11());

System.out.println("老平台出、入金存储过程的执行结果是:"+result);

} catch (SQLException e) {

e.printStackTrace();

}finally{

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

return result;

}

--后来增加判断:若连接为空,则重新通过jdbc连接,暂时未出现连接超时问题

public String execute(Entity entity) {

Session session = (Session) this.getJpa().getManager().getDelegate();

SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory();

Connection conn = null;

String result = null;

try {

conn = sessionFactory.getConnectionProvider().getConnection();

if (conn == null || conn.isClosed()) {

try {

Class.forName(driverClass);

conn = DriverManager.getConnection(url, username, password);

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

}

} catch (SQLException e1) {

e1.printStackTrace();

}

try {

//   conn = sessionFactory.getConnectionProvider().getConnection();

CallableStatement call = conn.prepareCall("{call SP_FORMER_BMP_INFO_AUDIT(?,?,?,?,?,?,?,?,?,?,?,?)}");

call.setString(1, entity.getParam1());

call.setString(2, entity.getParam2());

call.setString(3, entity.getParam3());

call.setString(4, entity.getParam4());

call.setString(5, entity.getParam5());

call.setString(6, entity.getParam6());

call.setString(7, entity.getParam7());

call.setString(8, entity.getParam8());

call.setString(9, entity.getParam9());

call.setString(10, entity.getParam10());

call.setString(11, entity.getParam11());

call.registerOutParameter(12, Types.VARCHAR);

call.execute();

result = call.getString(12);

System.out.println("老平台出、入金存储过程的执行结果是:"+result);

} catch (SQLException e) {

e.printStackTrace();

}finally{

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

return result;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值