Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

java - Get Bind Variables In Oracle JDBC Logging

I am trying to debug my Java application that queries an Oracle database.

I have started my application with

-Doracle.jdbc.Trace=true  -Djava.util.logging.config.file=c:/tmp/oracledebug.properties  

Containing

handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.pattern = c:/tmp/jdbc.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
oracle.jdbc.driver.level = CONFIG

However, it outputs the SQL with question marks.

Is it possible to log the values of the bind variables?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to the documentation:

FINE Logs the entry and exit to every public method providing a detailed trace of JDBC operations. It produces a fairly high volume of log messages.

Set the system property -Djava.util.logging.SimpleFormatter.format="%1$tc %2$s %3$s%n%4$s: %5$s%6$s%n" to include the logger name in your output file.

When I set the oracle.jdbc.driver=FINE using the above SimpleFormatter pattern I see output like:

Wed Nov 02 08:43:06 CDT 2016 oracle.jdbc.driver.OraclePreparedStatement setString oracle.jdbc.driver
FINE: XXXXXXXX Public Enter: 1, "some input string"

Everything after Public Enter: are the arguments to PreparedStatement.setString(int, String).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...