logback and mysql Connections could not be acquired

12,415

Solution 1

The problem was that I missed logback-examples-1.0.0.jar

Solution 2

I got this error

java.lang.IllegalStateException: DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method and without a specific SQL dialect

The reason was, I have seted a wrong connection URL for DriverManagerConnectionSource. There was no any DB server with that URL. Unfortunately the logback is confusing us with a wrong error message

Solution 3

i had a similar error pop up, and it was simply a configuration error.... The "driverClass" was wrong in my xml config file.... I didn't notice right off because I took it from an existing project where I assumed it worked...

So long story short, make sure you're driverClass is:

com.mysql.jdbc.Driver

if you're trying to connect to mysql!

Solution 4

The root cause is right at the bottom of your log snippet:

ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:13 - RuntimeException in Action for tag [appender] java.lang.IllegalStateException: DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect

You'll have to specify a MySQL dialect in the configuration for DBAppender.

See this: http://logback.qos.ch/manual/appenders.html#DBAppender

Share:
12,415
Dejell
Author by

Dejell

I like traveling around the world. So far I have been to: USA England Italy Slovania Croatia Jordan South Africa Zimbabwe Botswana France Canada Israel Thailand Switzerland Holland Bulgaria I am going to Vietnam soon

Updated on June 24, 2022

Comments

  • Dejell
    Dejell almost 2 years

    I am using logback and mysql like this:

    <appender name="db" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
            <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
                <driverClass>com.mysql.jdbc.Driver</driverClass>
                <jdbcUrl>${jdbc.url}</jdbcUrl>
                <user>${jdbc.username}</user>
                <password>${jdbc.password}</password>
            </dataSource>
    
        </connectionSource>
    </appender>
    

    However I get:

        11:51:45,851 |-WARN in ch.qos.logback.core.db.DataSourceConnectionSource@4c1be833 - Could not get a connection to discover the dialect to use. java.sql.SQLException: Connections could not be acquired from the underlying database!
        at java.sql.SQLException: Connections could not be acquired from the underlying database!
        at  at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
        at  at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
        at  at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        at  at ch.qos.logback.core.db.DataSourceConnectionSource.getConnection(DataSourceConnectionSource.java:72)
        at  at ch.qos.logback.core.db.DataSourceConnectionSource.start(DataSourceConnectionSource.java:46)
        at  at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:167)
        at  at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:318)
        at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:197)
        at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:183)
        at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
        at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:147)
        at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:133)
        at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:96)
        at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:55)
        at  at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
        at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
        at  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:54)
        at  at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
        at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
        at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
        at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
        at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
        at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
        at  at com.grroo.manager.impl.AmazonEmailManagerImpl.<init>(AmazonEmailManagerImpl.java:42)
        at  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at  at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
        at  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
        at  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
        at  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
        at  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
        at  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
        at  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at  at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
        at  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
        at  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
        at  at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
        at  at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
        at  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at  at java.lang.Thread.run(Thread.java:662)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
        at  at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
        at  at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        at  at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
        at  at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
        at  ... 51 common frames omitted
    11:51:45,851 |-WARN in ch.qos.logback.core.db.DataSourceConnectionSource@4c1be833 - Connection does not support GetGeneratedKey method and could not discover the dialect.
    11:51:45,854 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:13 - RuntimeException in Action for tag [appender] java.lang.IllegalStateException: DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect
        at java.lang.IllegalStateException: DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect
        at  at ch.qos.logback.core.db.DBAppenderBase.start(DBAppenderBase.java:62)
        at  at ch.qos.logback.classic.db.DBAppender.start(DBAppender.java:96)
        at  at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
    

    What is wrong? I am using mysql-connector-5.0.08 and the database is mysql 5.0.51

    EDITED:

    I tried to add <sqlDialect class="ch.qos.logback.core.db.dialect.MySQLDialect" /> like this:

    <appender name="db" class="ch.qos.logback.classic.db.DBAppender">
            <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
                <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
                    <driverClass>com.mysql.jdbc.Driver</driverClass>
                    <jdbcUrl>${jdbc.url}</jdbcUrl>
                    <user>${jdbc.username}</user>
                    <password>${jdbc.password}</password>
                </dataSource>
    
            </connectionSource>
                    <sqlDialect class="ch.qos.logback.core.db.dialect.MySQLDialect" />`
        </appender>
    

    But with no success!