Java調用預存程序,隨著按鈕點擊增多,調用預存程序也增多,會出現逾時問題

來源:互聯網
上載者:User

標籤:manager   his   tde   sed   varchar   otf   use   out   bmp   

剛開始代碼是這樣的直接通過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;
 }

 

Java調用預存程序,隨著按鈕點擊增多,調用預存程序也增多,會出現逾時問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.