Debug your JDBC API program
There are two mechanisms to generate trace outputs in JDBC. A legacy mechanism SQLDEBUG and a more modern use of a logging framework.
JDBC Tracing Using Logging
You can enable tracing of the JDBC driver via the logging API Log4j. For JDBC versions 8.1.1.2 and above you will need to include the optional logging library which is found at https://search.maven.org/artifact/org.apache.logging.log4j/log4j-core/2.17.1/jar alongside the JDBC jar file in yoru CLASSPATH.
This file must exist in the CLASSPATH of the running application or be specified using the
Java system property log4j2.configurationFile=/path/to/log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <Configuration monitorInterval="30" status="WARN"> <Property name="pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5level | %t | %c{1} | %method | %marker | %msg%n</Property> <Appenders> <File name="console" fileName="/tmp/onedb-jdbc.log"> <PatternLayout pattern="${pattern}" /> </File> </Appenders> <Loggers> <!-- Change this to 'trace' to print out driver events --> <Root level="trace" additivity="false"> <AppenderRef ref="console" /> </Root> </Loggers> </Configuration>
If you already using Log4j or another logger you can enable JDBC logging by enabling trace events on the JDBC packages.
For more information on the customization and options available using Log4j refer to the Log4j configuration guide at https://logging.apache.org/log4j/2.x/manual/configuration.html
Package Name |
---|
com.onedb.jdbc |
com.onedb.jdbcx |
com.informix |
SQLIDEBUG
SQLIDEBUG=/tmp/jdbctrace.log
A new trace file is generated for every connection and is suffixed with a timestamp. If you are using the OneDBDataSource class, you can use the OneDBDataSource.setPropery("SQLIDEBUG", "/tmp/jdbctrace.log") method.