Java calls stored procedures, with the number of button clicks, the call stored procedures also increased, there will be a timeout problem

Source: Internet
Author: User

Just start the code is like this directly through the JPA connection, just beginning to click on the button to call the stored procedure, no problem, and so many clicks will not respond: Log Report database connection timeout:

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 (ENTITY.GETPARAM10 ());
Call.setstring (one, ENTITY.GETPARAM11 ());
Call.registeroutparameter (Types.varchar);
Call.execute ();

   result = call.getstring (12);
   system.out.println ("parameter:" +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 ("The execution result of the old platform out and deposit process is:" +result);
  } catch (SQLException e) {
   e.printstacktrace ();
  }finally{
   IF (conn! = null) {
    try {
      conn.close ();
    } catch (SQLException e) {
     e.printstacktrace ();
    }
   }
  }
  
  return result;
 }

--later added judgment: If the connection is empty, then the JDBC connection is re-connected and the connection timeout is not present.

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 (ENTITY.GETPARAM10 ());
Call.setstring (one, ENTITY.GETPARAM11 ());
Call.registeroutparameter (Types.varchar);
Call.execute ();

result = Call.getstring (12);

System.out.println ("The execution result of the old platform out and deposit process is:" +result);
} catch (SQLException e) {
E.printstacktrace ();
}finally{
IF (conn! = null) {
try {
Conn.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}
}

return result;
}

Java calls stored procedures, with the number of button clicks, the call stored procedures also increased, there will be a timeout problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.