[logback-user] DB Appender with H2

Ceki Gülcü ceki at qos.ch
Thu Jan 28 08:29:12 CET 2010


You can find the hsqldb.sql file under http://tinyurl.com/y9mq4pa

Looking at the H2 docs [1], the IDENTITY() method serves exactly the same 
purpose as in HSQL. So the H2 dialect would be the same as HSQL. I think the sql 
for creating the schema should be the same as well.

So assuming the above to be correct, after you create the appropriate tables 
using the sql found in hsqldb.sql and creating H2Dialect.java (copy and paste 
HSQLDialect.java), you would need to integrate the H2Dialect with logback. This 
can be done by adapting DBUtil.java under ch.qos.logback.core.db.dialect which 
should be pretty trivial.


[1] http://www.h2database.com/h2.pdf

On 28/01/2010 7:39 AM, Ceki Gülcü wrote:
> 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)
>>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list