-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem establishing a connection with MySql database
PostPosted: Tue Jul 14, 2009 5:28 am 
Newbie

Joined: Tue Jul 14, 2009 5:17 am
Posts: 1
Hi,

I'm a student and I am trying to create a simple online questionnaire to collect information for a final year dissertation.

I have wrote a small application using Struts, JSP, Hibernate to connect to a MySQL database.

The application is running fine on my local development machine, but when I try to deploy it to my hosting company, I am getting the following error whenever the application is trying to save or query the Database.


Code:
2009-07-14 10:12:30,828 ERROR org.hibernate.util.JDBCExceptionReporter - Communications link failure

Last packet sent to the server was 78 ms ago.
2009-07-14 10:12:30,875 ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.JDBCConnectionException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at com.questionnaire.core.manager.QuestionnaireManager.saveQuestionnaire(QuestionnaireManager.java:25)
   at com.questionnaire.model.QuestionnaireModel.saveQuestionnaire(QuestionnaireModel.java:59)
   at com.questionnaire.struts.action.QuestionnaireAction.submitQuestionnaireForm(QuestionnaireAction.java:57)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Communications link failure

Last packet sent to the server was 78 ms ago.
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
   ... 36 more
2009-07-14 10:12:32,750 ERROR org.hibernate.transaction.JDBCTransaction - JDBC rollback failed
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
   at com.mysql.jdbc.ConnectionImpl.getMutex(ConnectionImpl.java:3018)
   at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4564)
   at org.hibernate.transaction.JDBCTransaction.rollbackAndResetAutoCommit(JDBCTransaction.java:183)
   at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:162)
   at com.questionnaire.core.manager.QuestionnaireManager.saveQuestionnaire(QuestionnaireManager.java:28)
   at com.questionnaire.model.QuestionnaireModel.saveQuestionnaire(QuestionnaireModel.java:59)
   at com.questionnaire.struts.action.QuestionnaireAction.submitQuestionnaireForm(QuestionnaireAction.java:57)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
   at java.lang.Thread.run(Unknown Source)



This is what I have in my hibernate.cfg.xml file:

Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

   <session-factory>
   
      <property name="connection.username">stratheg_admin</property>
      <property name="connection.url">jdbc:mysql://localhost:3306/stratheg_Questionnaire</property>   
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="myeclipse.connection.profile">stratheg_Questionnaire</property>
      <property name="connection.password">XXXXXXXX</property>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
   
      <mapping resource="com/questionnaire/core/hibernate/Questionnaire.hbm.xml" />

   </session-factory>

</hibernate-configuration>


This is how I am saving to the Database:

Code:
   public void saveQuestionnaire(Questionnaire questionnaire) throws HibernateException {
      Session hibernateSession = null;
      Transaction transaction = null;
      try {
         logger.info("saving questionnaire");
         
         hibernateSession = HibernateSessionFactory.getSession();
         transaction =hibernateSession.beginTransaction();
         this.saveQuestionnaire(questionnaire, hibernateSession);
         transaction.commit();
      } catch (HibernateException he) {
         if (transaction != null) {
            transaction.rollback();
         }
         logger.error("Exception thrown when trying to save questionnaire:  "+he.getMessage());
         throw he;
      } finally {
         hibernateSession.close();
      }
      
   }
   
   private void saveQuestionnaire(Questionnaire questionnaire, Session hibernateSession) throws HibernateException {
      try {
         hibernateSession.save(questionnaire);
      } catch (HibernateException he) {
         logger.error("Exception thrown when trying to save questionnaire:  "+he.getMessage());
         throw he;
      }
   }


Sorry for all the code, but I am trying to give as much information as I can so that hopefully someone will recognise or spot an error...
Again, this code is working fine on my local machine, but fails when deployed onto the hosting server.

Any suggestion as to the problem is most welcomed.

Thanks
-Ko


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.