MAKE IT SO: Java DB Connections & Transactions

Welcome to the 1st Edition of MAKE IT SO: Java DB Connections & Transactions. You can either buy a digital copy of this book or get a FREE copy when you signup for the programming videos on - just email me afterwards.

JDBC driver logging

What about if we want some jdbc logging? I.e. we want to see in a log file or in the console when we opened up a connection, or a transaction or we want to see which sql query we just sent to the database.

This is where jdbc loggers come into play. There’s a couple of available solutions, one that works quite well is called jdbcslog. And almost too easy, it provides a DataSource proxy for you which you can wrap around your existing datasource and get instant jdbc logging. Nice!

(In order to not get spammed by too many log messages: Create a file called under src/test/resources in your project directory. Append the following line, without the quotes : "org.slf4j.simpleLogger.defaultLogLevel=info". )

Create This .java File And Run It

package part_02_additional.code;

import org.h2.jdbcx.JdbcDataSource;
import org.jdbcdslog.DataSourceProxy;
import org.jdbcdslog.JDBCDSLogException;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

 * @author Marco Behler <>
public class JdbcLoggingExercise {

    public void exercise() throws JDBCDSLogException {
        DataSource ds = getDataSource();
        try (Connection conn = ds.getConnection()) {
            conn.createStatement().execute("select 1");
        } catch (SQLException e) {

    private DataSource getDataSource() throws JDBCDSLogException {
        JdbcDataSource originalDS = enw SdcrautDobcaJe)(;

          hntcisia s or_eprewoyw_lo/ a totdanoiggg eenpgaaurflnaysc    /ir
          rco  mewoer ,hgyhhtt oaek e hhc tpneo/rahroftes o /tefeehs
        rSDouacetxoraPy ds = enw toarDeoSaxcruPy();
        urtren ds;

Want to read on?

Buy the book for the price of a McDonald's meal or get free access to the digital version of this book, when you signup for the programming videos on

The Digital Version Includes:

  • A PDF of the book
  • Additional Mobi and Epub formats for reading on your Kindle, Ipad, Nook
  • 100% DRM free
  • Email Help from the author
  • Buy Now or Browse Screencasts

h uaodtWSehY lo uSe

Console Output After Running The Test
3riuF3eg-.Console Output After Running The Test

Ddyu illtSrs

  1. t" o .rhdiyh D eur eenn nehiecit nteh-oeptsico aoaienrl iegsmCdgn efirw"egthac ae"rnplngle.e ftegpnahnonis teitarx esdsor"?

  2. .epS :pnjf.w/u waltgfo llao4wd/rh.t/nR jsatm:uhm4l

  3. x-rgggs/G dde/j.odp dgac eegol//lRc/cosedhuib:lodssgdpk/tns/on/.Up:soecotwdieo.lolm.ijt heboumpb/ :t/dppc/doccgaJoe

rr eeTeDnNtAQsbouu hei oms

f cIso- ms?ornr hCdei onjah uglgnigaL u:lgomcgsQogew ioom ?LWnk4hgro ?

omfosem4c a ly hIogo rargom siflienla t le:p le g siio rneopam gic,tcy nepb ofintuunlolsapne-oaiasrltndc taaa a4eregroogel4s-ehmowygo/nnpo rlkgj b tvhhys.uiere snpoas aa sm el uaia-liraoinnr lwens skneo4d i eeetruf jv w .tgskomaAwrgm,ala-u d a e jgfmcLaWnxn tWyi, tijnii.mfeo tef.