Sybase jConnect 6.0 comes with several examples and I kind of thought this debugging example might prove valuable. The main goal of this exercise was to get parameter substitution working when queries are envoked to simplify debugging via logging. It looked like it could be promising from the documentation, and it was very easy to setup, provided you had the jconn3d.jar.
final String url = "jdbc:sybase:Tds:localhost:5003/database";
final String classes = "SybConnection:SybStatement:Debug:STATIC";
final SybDriver sybDriver = (SybDriver) DriverManager.getDriver(url);
final Debug logger = sybDriver.getDebug();
logger.debug(true, classes);
The debug library produced lots of information about what was happening, unfortunately, it was very chatty and not very descriptive; it printed out conversion and type information, but as codes rather than the “readible” values, and the worst part was that none values were displayed.
com.sybase.jdbc3.jdbc.SybConnection(Thread[main,5,main]): autocommit state is: true
com.sybase.jdbc3.jdbc.SybConnection(Thread[main,5,main]): initProtocol()
(Thread[main,5,main]): processEscapes( {call STP1(?, ?, ?, ?, ?)} )
(Thread[main,5,main]): converted buffer = 'STP1 ?, ?, ?, ?, ?, ?'
(Thread[main,5,main]): numString(5) --> 5
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 9
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 4
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 9
(Thread[main,5,main]): dataTypeInfo Param: 12, converted to TDS type 39, length = 32
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 1, converted to TDS type 39, length = 0
(Thread[main,5,main]): dataTypeInfo Param: 4, converted to TDS type 38, length = 0
Another really nice option seems to be the log4jdbc
library. It is also very easy to use; just change a couple JDBC
configuration properties. It actually provided all of the information
we were looking for and quickly integrated with our Spring and
Hibernate environment. It was highly configurable, and one of the
nicest things was that it would actually provide “timings” on all of
the executed sql. The seems like a really good tool to use during
development and testing, not sure if I would run it in a production
environment; I guess it depends on the requirements of the system.
FINE 10/29/2007 09:58:33 AM [Slf4jSpyLogDelegator.sqlTimingOccured()][main]
org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
2. {STP_Name('111129922', '5', '144808258', 'DM043BD4C600006EDC00000001 ', <out>, <out>,
<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,<out>,, )} {executed in 79 msec}