First I'd like to thank everyone for their help so far. The application is now accessible and connecting to the database.
Problem I am now facing however, is trying query or save to the database.
I get the following error message whenever I try to save.
Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
The application is written using Struts, JSP, and Hibernate to connect to a MySQL database. Everything works perfectly on my local machine. However, whenever I try to run it on the hosted site I get the above error.
This is the code I use for saving to the database:
Code:
package com.questionnaire.core.manager;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.questionnaire.core.dto.Questionnaire;
import com.questionnaire.core.hibernate.HibernateSessionFactory;
public class QuestionnaireManager {
public void saveQuestionnaire(Questionnaire questionnaire) throws HibernateException {
Session hibernateSession = null;
Transaction transaction = null;
try {
hibernateSession = HibernateSessionFactory.getSession();
transaction =hibernateSession.beginTransaction();
this.saveQuestionnaire(questionnaire, hibernateSession);
transaction.commit();
} catch (HibernateException he) {
if (transaction != null) {
transaction.rollback();
}
throw he;
} finally {
hibernateSession.close();
}
}
private void saveQuestionnaire(Questionnaire questionnaire, Session hibernateSession) throws HibernateException {
try {
hibernateSession.save(questionnaire);
} catch (HibernateException he) {
throw he;
}
}
}
Any help is much appreciated.
Thanks,
Ko