2014-07-19 16 views
6

erworben werden Ich bin mit Hibernate, MySQL-Verbindung gültig ist, aber ich folgende bekommen. Wie kann ich weitere Details zu Verbindungszeichenfolgen sehen, mit denen eine Verbindung hergestellt wird?java.sql.SQLException: Verbindungen konnten nicht von der zugrunde liegenden Datenbank

ERROR SchemaUpdate - could not get database metadata 
java.sql.SQLException: Connections could not be acquired from the underlying database! 
     at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) 
     at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) 
     at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78) 
     at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) 
     at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:168) 
     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:356) 
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) 
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.awaitAvailable(BasicResourcePool.java:1319) 
     at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) 
     at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) 
     ... 10 more 
ERROR SchemaUpdate - could not complete schema update 
java.sql.SQLException: Connections could not be acquired from the underlying database! 
     at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) 
     at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) 
     at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78) 
     at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) 
     at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:168) 
     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:356) 
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) 
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.awaitAvailable(BasicResourcePool.java:1319) 
     at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) 
     at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) 
     ... 10 more 

ERROR JDBCExceptionReporter - Connections could not be acquired from the underlying database! 
org.hibernate.exception.GenericJDBCException: Cannot open connection 
     at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) 
     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) 
     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) 
     at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) 
     at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) 
     at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) 
     at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) 
     at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342) 
     at com.sun.proxy.$Proxy0.beginTransaction(Unknown Source) 

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! 
     at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) 
     at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) 
     at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78) 
     at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) 
     ... 15 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.awaitAvailable(BasicResourcePool.java:1319) 
     at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) 
     at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) 
     at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) 
     ... 18 more 

hier ist meine Hibernate xml:

<hibernate-configuration> 
    <session-factory> 

     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/test</property> 

     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.connection.password">xxxxxx</property> 

     <property name="show_sql">false</property> 
     <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hibernate.hbm2ddl.auto">update</property> 
     <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
     <property name="hibernate.c3p0.max_statements">200</property> 

     <property name="hibernate.c3p0.min_size">20</property> 
     <property name="hibernate.c3p0.max_size">200</property> 
     <property name="hibernate.c3p0.idle_test_period">300</property> 
     <property name="hibernate.c3p0.timeout">300</property> 

     <property name="hibernate.c3p0.max_statements">200</property> 
     <property name="current_session_context_class">thread</property> 

    </session-factory> 
</hibernate-configuration> 
+0

geschieht dies auf jeder Operation oder nur einige Male? – bitkot

+0

@AmitChotaliya es die ganze Zeit passiert, kann ich jdbc verbinden: mysql: // localhost: 3306/test und jdbc: mysql: //127.0.0.1: 3306/Test ohne Frage auf der Befehlszeile Ports offen sind – user121196

+0

Okay, Ich habe das gefragt, weil dies passiert, wenn Sie Verbindungen ausschöpfen. d. h. in c3p0 haben Sie 200 Verbindungen erlaubt, aber mysql default max 151, wenn Sie also danach versuchen, dann erhalten Sie diesen Fehler. – bitkot

Antwort

2

Ich werde zwei Dinge empfehlen dieses Problem gelöst zu bekommen: zunächst Ihre Datenbank Name in Großbuchstaben zu erwähnen. Obwohl db die Groß-/Kleinschreibung immer noch nicht beachtet, läuft es manchmal gut mit Großbuchstaben.

Zweitens kann dieses Problem auftreten, weil einige zusätzlichen Dinge, die Sie mit Ihrer Sitzung Fabrik Wert angehängt haben könnten. Zum Beispiel (i Code nehmen werde ich verwendet, und konfrontiert dieses Problem und das habe es los): Teil meiner xml so geht:

<session-factory> 
    <property name="hbm2ddl.auto">update</property> 
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
    <property name="connection.url">jdbc:mysql://10.184.56.183:3306/******?relaxAutoCommit=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8</property> 
    <property name="connection.username">******</property> 
    <property name="connection.password">******</property> 
    <property name="hibernate.show_sql">true</property> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="hibernate.current_session_context_class">thread</property> 
    <property name="hibernate.connection.pool_size">5</property> 
    <property name="hibernate.connection.shutdown">true</property> 
    <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> 
    <property name="hibernate.cache.use_second_level_cache">false</property> 
    <property name="hibernate.cache.use_query_cache">false</property> 
    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
    <property name="hibernate.c3p0.min_size">2</property> 
    <property name="hibernate.c3p0.max_size">5</property> 
    <property name="hibernate.c3p0.timeout">108000</property> 
    <property name="hibernate.c3p0.max_statements">50</property> 
    <property name="hibernate.c3p0.idle_test_period">1000</property> 
    <property name="hibernate.c3p0.validate">true</property> 
    <property name="hibernate.c3p0.acquire_increment">5</property>  

So zusätzliche Werte halten Trimmen wie sauber Ihre Datenbankverbindung URL und andere Sachen. Ich hatte Probleme beim Erzeugen von Code aus der Datenbanktabelle. Also habe ich eine andere Konfigurations-XML erstellt und das so einfach wie möglich gemacht und das wars. Es ging sehr gut.

+1

Benutzer mit roo @ localhost und nicht root @% sollte es keine Antwort kommentieren werden! – Hamad

+0

Hey @ Hamad, ist das jetzt in Ordnung? oder soll ich das zum kommentieren ändern? –

1

In meinem Fall war es Problem, dass c3p0-0.9.2.1.jar Datei nicht von Maven in src/main/webapp/web-inf/libs

1

kopiert wurde, hatte ich dieses Problem und das Problem war Adresse unser Büro IP von MySQL-Server aufgrund vieler blockiert Verbinde Versuche mit schlechten Anmeldeinformationen.

Vergewissern Sie sich mit dem Server verbinden können die gleiche Methode/Netzwerk wie Ihre Anwendung. Wenn Sie dies oder ähnliches erhalten, wenn mit einigem MySQL-Client versucht, eine Verbindung (wie Workbench)

Host 'XXX-XXX-XXX-XXX.static.XXXXXX.XXX' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 

Ihre IP blockiert, und das ist das Problem.

Verwandte Themen