views:

1658

answers:

2

I am using Hibernate 3 +Mysql 5.1 and after 98 insertion i am getting this Exception :

com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"

My hibernate.cfg.xml file is :

com.mysql.jdbc.Driver jdbc:mysql://localhost/xml root root 10 false org.hibernate.dialect.MySQLDialect update true

+1  A: 

I'd guess your application is leaking connections (opens them without properly closing them).

ammoQ
+2  A: 

Do you close your connections in a finally block?

something like this?

Session sess = factory.openSession();
Transaction tx;
try {
   tx = sess.beginTransaction();
   //do some work
   ...
   tx.commit();
}
catch (Exception e) {
   if (tx!=null) tx.rollback();
   throw e;
}
finally {
   sess.close();
}

If you don't you will be running out of connections.

HeDinges