This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Hibernate exception occured after 1 hr running in server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Hibernate exception occured after 1 hr running in server" Watch "Hibernate exception occured after 1 hr running in server" New topic
Author

Hibernate exception occured after 1 hr running in server

kiran gk
Greenhorn

Joined: May 09, 2012
Posts: 5
hi everyone,

I deployed my code in server it works fine till some time say 1 hour but after that it gives org.hibernate.exception.JDBCConnectionException: Cannot open connection Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Too many connections

How to avoid this exception ??? any help ??

---------- error message is--------------------------

entering main
configuration is done
connection got
query executed
Coefficent 1 is :5
Coefficent 0 is :5
Device ID is : 201001000002
Sensor type is : O3
SO2,EC4-20-SO2
entering main
configuration is done
connection got
Hibernate exception occured
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at FetchCoeff.testing(FetchCoeff.java:37)
at UDPServer.main(UDPServer.java:70)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Too many connections
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:985)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:894)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1256)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor17.newInstance(Unknown
Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:169)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
... 6 more
Exception in thread "main" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1009)
at java.lang.Float.parseFloat(Float.java:439)
at ConvertReadings.Convertd(ConvertReadings.java:52)
at UDPServer.main(UDPServer.java:72)



hibernate configuration file is


<?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">

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/kiran
</property>
<property name="connection.username">
kiran
</property>
<property name="connection.password">
kiran123
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">false</property>
<mapping resource="SensorReadings.hbm.xml"/>
</session-factory>
</hibernate-configuration>



the fetching code is




/**
*
*/

/**
*
*
*/
import java.util.Iterator;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;



public class FetchCoeff {
public String[] testing(String x, String y) { ///here x=DevID and y= sensor type
Session session= null ;
Transaction tx= null;
String c[] = new String[30];


System.out.println("entering main");
Logger.getRootLogger().setLevel(Level.OFF);
Configuration cfg= new Configuration();
cfg.configure("Hibernate.cfg.xml");
System.out.println("configuration is done");
session = cfg.buildSessionFactory().openSession();
System.out.println("connection got");
try{
tx = session.beginTransaction();
String q= "SELECT d.c1, d.c0, d.DevID, d.SensorType FROM SensorReadings d WHERE d.DevID= evID AND d.SensorType= :SensorType";
Query query = session.createQuery(q);
query.setParameter("DevID",x);
query.setParameter("SensorType", y);
System.out.println("query executed");
for(Iterator it=query.iterate();it.hasNext();){
Object[] ob = (Object[]) it.next();
System.out.println("Coefficent 1 is :" + ob[0]);
System.out.println("Coefficent 0 is :" + ob[1]);
System.out.println("Device ID is : " + ob[2]);
System.out.println("Sensor type is : " + ob[3]);
c[1]= (String)ob[0]; // contains coeff 1 c1
c[0]= (String)ob[1]; // contains coeff 0 c0
tx.commit();
}
}catch(HibernateException e){
System.out.println("Hibernate exception occured");
e.printStackTrace();
}catch(Exception d){
System.out.println("exception occured");
d.printStackTrace();
}
finally
{
session.close();
}
return c;
}
}




Can anyone help me in solving this problem ???
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Have a look at this thread: http://www.coderanch.com/t/425768/JDBC/java/Too-many-connections
 
Don't get me started about those stupid light bulbs.
 
subject: Hibernate exception occured after 1 hr running in server
 
Similar Threads
Cannot add or update a child row: a foreign key constraint fails
Schema Export Unsuccesful
Problem with MySql Connections in servlet application
Error connecting on MySQL
NULL POINTER EXCEPTION IN HIBERNATE