ログ出力
log4j で簡単にログ出力できます。
DBIにログ設定したり、Handleにもログ設定できます。
必要なところだけロギングしたければHandleに設定すればよいでしょう。
log4j.jar をクラスパスに加えないとコンパイルできないかもしれませんのでご注意を。
Sample028.java
private static DBI getDBI() { return new DBI("jdbc:postgresql://192.168.52.128/jdbi", "jdbi_user", "jdbi_pass"); } public static void main(String[] args) { BasicConfigurator.configure(); logAtDBI(); logAtHandle(); } private static void logAtDBI() { DBI dbi = getDBI(); dbi.setSQLLog(new Log4JLog()); dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle h) throws Exception { h.execute("truncate table table001"); h.insert("insert into table001(id, name) values(?,?)", 1, "name1"); h.select("select * from table001 where id = ?", 1); return null; } }); } private static void logAtHandle() { DBI dbi = getDBI(); dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle h) throws Exception { h.update("update table001 set name = 'name100' where id = 1"); h.createStatement("select * from table001 where id = :id").bind("id", 1).execute(); h.setSQLLog(new Log4JLog()); h.update("delete from table001 where id = ?", 1); h.execute("select * from table001"); return null; } }); }