<appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <dataSource class="org.apache.commons.dbcp.BasicDataSource"> <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName> <url>jdbc:oracle:thin:@localhost:1521:ZYD</url> <user>scott</user> <password>tiger</password> </dataSource> </connectionSource> </appender> <appender-ref ref="db-classic-oracle" />
以上是按官方文档配置的,但启动服务器后就报错!!!!
错误如下:
10:38:47,746 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@42:16 - 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
貌似是你的数据库方言配置错了。
那怎么配置呢
??
@血屠: 我没用过哈,你跟着官方的配置文档配置下呗,同时注意下你自己的包版本和文档的版本是否对应。
@血屠: 检查下你的connectionSource节点是否配置错了。
试下如下内容呢:<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
@幻天芒: 还是不行,报错更厉害了……
@血屠: 那你得自己查查了,主要是官方文档。
@幻天芒: 终于解决了……加了个 方言
<sqlDialect class="ch.qos.logback.core.db.dialect.OracleDialect" />
然后把<driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
改成了<driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
@血屠: 不错,是参考文档来的吗?博客园搞java的相对比较少,呵呵~
@幻天芒: 我去Stack overflow网站上看到的,终于解决了……
@血屠: 这网站不错,呵呵~
正确配置应该是
<!-- 将日志存储到oracle数据库中 --> <appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource"> <driverClass>oracle.jdbc.driver.OracleDriver</driverClass> <url>jdbc:oracle:thin:@localhost:1521:ZYD</url> <user>scott</user> <password>tiger</password> <sqlDialect class="ch.qos.logback.core.db.dialect.OracleDialect" /> </dataSource> </connectionSource> <sqlDialect class="ch.qos.logback.core.db.dialect.OracleDialect" /> </appender>