File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Problems to connect to mysql with hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problems to connect to mysql with hibernate" Watch "Problems to connect to mysql with hibernate" New topic

Problems to connect to mysql with hibernate

Fabio Batalha

Joined: Aug 11, 2004
Posts: 6
Please, someone cold help me with this problem?

I�m having problems to connect to my database using hibernate. This is the problem:

Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.jdbc.ConnectionManager.openConnection(
at org.hibernate.jdbc.ConnectionManager.getConnection(
at org.hibernate.jdbc.JDBCContext.connection(
at org.hibernate.transaction.JDBCTransaction.begin(
at org.hibernate.impl.SessionImpl.beginTransaction(
at org.bireme.scieloorgupdate.Teste.main(
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(
at org.hibernate.jdbc.ConnectionManager.openConnection(
... 5 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(
... 8 more

This is my hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<property name="hibernate.dialect">
<property name="hibernate.connection.driver_class">
<property name="hibernate.connection.url">
<property name="hibernate.connection.username">
<property name="hibernate.connection.password">
<!-- Condigura��o do c3p0 -->
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- Configura��es de debug -->
<property name="show_sql">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.use_sql_comments">true</property>
<mapping resource="profiles.hbm.xml"/>
<mapping resource="articles.hbm.xml"/>
<mapping resource="profile_article.hbm.xml"/>

Fabio Batalha
Fabio Batalha

Joined: Aug 11, 2004
Posts: 6
Tks everybody

I already solve the problem the hibernate.connection.url was wrong!
kamal raja

Joined: May 10, 2009
Posts: 2

I got the same exception & resolved the issue after 3 hectic days.Check if you are using I hibernate3. In this version it is req to explicitly mention the connection class name. Also check if the jar is in classpath. Check steps & comments in below link

Remove autoReconnec=true
I agree. Here's the link:
subject: Problems to connect to mysql with hibernate
jQuery in Action, 3rd edition