Announcement Announcement Module
Collapse
No announcement yet.
com.mysql.jdbc.exceptions.MySQLNonTransientConnect ionExcept Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • com.mysql.jdbc.exceptions.MySQLNonTransientConnect ionExcept

    Hi,
    Iam getting the following error .
    Please suggest :

    2010-02-19 14:20:19,234 WARN - SessionImpl.finalize(3396) | unclosed connection
    com.mysql.jdbc.exceptions.MySQLNonTransientConnect ionException: No operations allowed after statement closed.
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:888)
    at com.mysql.jdbc.Statement.checkClosed(Statement.jav a:385)
    at com.mysql.jdbc.PreparedStatement.executeInternal(P reparedStatement.java:1361)
    at com.mysql.jdbc.PreparedStatement.executeQuery(Prep aredStatement.java:1467)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement .executeQuery(NewProxyPreparedStatement.java:76)
    at org.ariose.dao.hibernate.ServiceLogDAOHibernate.ge tServiceData(ServiceLogDAOHibernate.java:37)
    at org.ariose.service.impl.ServiceLogManagerImpl.getS erviceData(ServiceLogManagerImpl.java:25)
    at org.ariose.web.ServiceLogController.getServiceData (ServiceLogController.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.invokeNamedMethod(MultiActionC ontroller.java:472)
    at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.handleRequestInternal(MultiAct ionController.java:409)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:874)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:808)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:476)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:441)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)


    Here's the code :
    -----------------------
    public List<ServiceLogBean> getServiceData(List<String> contents) {
    List<ServiceLogBean> list=new ArrayList<ServiceLogBean>();
    PreparedStatement statement=null;
    ResultSet resultSet=null;
    Connection connection=null;
    try {
    ServiceLogBean logBean=null;
    connection=getHibernateTemplate().getSessionFactor y().openSession().connection();
    for(String content:contents){
    String query="select max(execute_time),count(execute_flag),(SELECT COUNT(1) FROM "+content+"_content ) as sCount" +
    " from "+content+"_content where execute_flag=1; ";
    System.out.println("Query:"+query);
    statement=connection.prepareStatement(query);
    resultSet=statement.executeQuery();
    logBean=new ServiceLogBean();
    while(resultSet.next()){
    if(resultSet.getString(1)!=null)
    logBean.setLastExecuteTime(resultSet.getString(1). substring(0,resultSet.getString(1).length()-2));
    logBean.setRecordsSent(resultSet.getInt(2));
    logBean.setTotalRecords(resultSet.getInt(3));
    logBean.setRecordsInQueue(resultSet.getInt(3)-resultSet.getInt(2));
    logBean.setServiceName(content);
    }
    list.add(logBean);
    resultSet.close();
    statement.close();
    }
    System.out.println(list);
    } catch (Exception e) {
    e.printStackTrace();
    }
    return list;
    }

    Please help...

  • #2
    Isn't there any body who can solve the above problem???

    Comment


    • #3
      Don't know about solving it, but here are a few suggestions:

      1. Please use the code tags around your code so it will format nicely.

      2. Watch out for sql injection vulnerabilities, especially if the user provides the values in your contents list.

      3. I'm a little confused about your while block. It looks like your while block ends right after: "logBean.setServiceName(content);" You are adding your logBean to your list outside of your loop, so only one logBean will be added to the list, and it will contain the information of the last processed item in your result set.

      I would guess you've got a few issues to fix with your while and if blocks. You'll want to make sure your statement and resultSet close methods are only invoked outside your loop (if you had planned to add an open bracket right after "if(resultSet.getString(1)!=null)").

      Comment


      • #4
        Hi ,
        Thanks for the reply.
        There is nothing wrong in the code.I will explain you the code which had confused you.
        Code:
        ServiceLogBean logBean=null;
        /*code used to get connection*/
        connection=getHibernateTemplate().getSessionFactor y().openSession().connection();
        
        /*I have a list which contains strings in it.Those strings are table names*/
        for(String content:contents){
        String query="select max(execute_time),count(execute_flag),(SELECT COUNT(1) FROM "+content+"_content ) as sCount" +
        " from "+content+"_content where execute_flag=1; ";
        
        statement=connection.prepareStatement(query);
        resultSet=statement.executeQuery();
        
        /*Iam creating a new pojo class to store the records for that table*/
        logBean=new ServiceLogBean();
        
        while(resultSet.next()){
        /*I had checked for null to avoid null pointer exception for substring*/
                  if(resultSet.getString(1)!=null)
        logBean.setLastExecuteTime(resultSet.getString(1).substring(0,resultSet.getString(1).length()-2));
        logBean.setRecordsSent(resultSet.getInt(2));
        logBean.setTotalRecords(resultSet.getInt(3));
        logBean.setRecordsInQueue(resultSet.getInt(3)-resultSet.getInt(2));
        logBean.setServiceName(content);
        }// END OF WHILE LOOP -NO MORE RECORDS FOR THAT TABLE
        list.add(logBean); // adding the pojo bean to list.
        resultSet.close();
        statement.close();
        }// CLOSE OF FOR LOOP

        Please let me know if iam doing any thing wrong here!!!!

        Comment

        Working...
        X