1

For some reason when I use:

connection = DriverManager.getConnection("jdbc:log4jdbc:derby:/home/user/mydb");

I tend to get differing connections back. In this case, it's a mixture between:

  1. connection = (org.apache.derby.impl.jdbc.EmbedConnection) org.apache.derby.impl.jdbc.EmbedConnection@2001280736 (XID = 598), (SESSIONID = 1), (DATABASE = /home/user/mydb), (DRDAID = null) - Which I don't want

and:

  1. connection = (net.sf.log4jdbc.ConnectionSpy) net.sf.log4jdbc.ConnectionSpy@32b260fa - Which I do want

To be more specific, when I run using a public static void main method then it works and I get back #2 but when I run the same code after running the web application's startup cycle then I get #1.

Is there a way to force log4jdbc to always return net.sf.log4jdbc.ConnectionSpy?

Hooli
  • 1,135
  • 3
  • 19
  • 46
  • Perhaps you have a different CLASSPATH in the different cases? Perhaps you are running with a different JDK in the different cases? Perhaps in one case you have registered a different set of JDBC drivers with DriverManager than in the other case? – Bryan Pendleton May 13 '16 at 13:42
  • Nope, same project, same code, same method even. Only difference is one where I run file the other where I run project. – Hooli May 13 '16 at 14:17

1 Answers1

0

I figured it out. You can force wrap the connection in this way:

Connection temp = DriverManager.getConnection("jdbc:log4jdbc:derby:/home/user/mydb");
connection = new net.sf.log4jdbc.ConnectionSpy(temp);
Hooli
  • 1,135
  • 3
  • 19
  • 46