[logback-user] DB Appender with H2

Ceki Gülcü ceki at qos.ch
Thu Jan 28 07:39:40 CET 2010


Hello Klaus,

The error message is pretty informative. DBAppender cannot function if
the JDBC driver does not support getGeneratedKeys method *and* without
a specific SQL dialect. As it appears that H2 does not support the
getGeneratedKeys method, an H2-specific dialect is required which at
present time logback does not have. Writing a dialect is equivalent to
implementing the getSelectInsertId() method in the SQLDialect
interface. There are a whole bunch of examples under the
ch.qos.logback.core.db.dialect package.

You need to learn how H2 allows you find out the id for last inserted
row and have the dialect return the corresponding SQL statement.

Of course you also need to create the database schema correctly. For
logback-classic, see the examples under
ch.qos.logback.classic.db.dialect.

For some reason the sql for creating the database schema for HSQL is
missing which is quite strange since logback uses HSQL for unit
testing DBAppender.  I'll add the missing HSQL-related files shortly.

I am mentioning HSQL because Thomas Mueller is the main author of both
H2 and HSQL . Thus, the HSQL dialect and database schema should be
particularly useful starting point for H2.

Cheers,

On 28/01/2010 5:09 AM, Klaus Teller wrote:
> Hi,
>
> Have anybody succeeded in using H2 as the underlying database for the logback databse appender? I'm getting the following exception and would very much appreciate  any input.
>
> Gregoire.
>
> -ERROR in ch.qos.logback.core.joran.spi.Interpreter at 43:14 - 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:59)
>      at     at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:92)
>      at     at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:307)



More information about the Logback-user mailing list