直到最近,我们为每个查询创建了一个新的数据库连接。每个查询都是使用connection.prepareStatement(query)设置的,我们能够使用prepareStatement.toString()将这些查询记录到我们的记录器(java.util.logging)中。这是使用 postgresql JDBC 驱动程序。
现在我们改用c3p0来管理连接池,不幸的是preparedStatement.toString()不再返回准备好的查询语句。
我读到 c3p0 日志记录可以定向到标准日志记录工具,但是不幸的是,我无法找到这些消息的去向。我在哪里可以找到这些消息? NetBeans 中的 Glassfish 3 控制台表明已启用调试。
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
Up until recently, we created a new database connection for every query. Each query is setup using connection.prepareStatement(query) and we were able to log these queries to our logger (java.util.logging) with preparedStatement.toString(). This was using the postgresql JDBC driver.
Now we've switched to using c3p0 to manage connection pools and unfortunately preparedStatement.toString() no longer returns the prepared query statement.
I have read that c3p0 logging can be directed to the standard logging facility but unfortunately I have been unable to find where these messages are going. Where can I find these messages? Glassfish 3's console in NetBeans states that debugging is enabled.
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
发布评论
评论(2)
我不确定 c3p0 的日志记录是否是您真正想要的?
我建议使用 log4jdbc,它可以记录任何 JDBC 查询(带参数),甚至提供即使您正在使用连接池(使用选项
-Dlog4jdbc.debug.stack.prefix=com.mycompany.myapp
)。它还可以显示计时信息等等。I'm not sure, if c3p0's logging is what you are really looking for?
I would recommend using log4jdbc, which can log any JDBC queries (with parameters), and even provide you with a stack trace pointing to your JDBC/Hibernate/... statement, even if you're using a connection pool (use the option
-Dlog4jdbc.debug.stack.prefix=com.mycompany.myapp
). It can also display timing information, and a lot more.日志记录似乎像日志中所说的那样(调试?true),但是如果您阅读 框 上,您将找到应检查以找到正确文件的设置选项。
如果您最终记录到所谓的最后手段选项,它应该记录到 System.Err ,这可能会导致问题:这篇文章告诉我们,System.Err默认情况下并不总是在任何日志文件中可见!
因此,请继续尝试前面提到的框中的其他选项,或使用我链接的帖子的答案部分的修复:)
The logging seems to be on like the log says (debug?true), but if you read the box on the link you had on your post you will find the setup options that should be checked for finding the right file.
If you end up logging to the so called last resort option, it should log to
System.Err
and this may cause the problem: this post tells that System.Err is not by default always visible in any log file!So keep trying the other options on the previously mentioned box or use the fix on the answer section of the post I linked :)