how to remove JDBC debug logs [duplicate] - java

This question already has an answer here:
Java tomcat - how to remove JDBC debug logs
(1 answer)
Closed 8 years ago.
The following log is constantly thrown to the console:
09:36:53.456 [CloseConnectionsTimer] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
09:36:53.456 [CloseConnectionsTimer] DEBUG o.s.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [0], value class [java.lang.Long], SQL type -5
09:36:53.456 [CloseConnectionsTimer] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
09:36:53.472 [CloseConnectionsTimer] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL query
09:36:53.472 [CloseConnectionsTimer] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL statement..
09:36:53.472 [CloseConnectionsTimer] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
09:36:53.472 [CloseConnectionsTimer] DEBUG o.s.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [0], value class [java.lang.Integer], SQL type 2
09:36:53.472 [CloseConnectionsTimer] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
How can i stop these logs/Change the logging level to INFO or ERROR?

Anything less than debug level will make those logs disappear. eg. INFO, WARN, ERROR

First of all, those are not JDBC logs, those are Spring logs.
Anyway, this should do the job in slf4j or log4j:
<logger name="org.spring.jdbc" level="OFF"/>

Related

P6Spy Spring Boot starter decorator produces empty output

I configured a Spring Boot starter P6Spy decorator as per the instructions on their site:
## p6spy ###
# Register P6LogFactory to log JDBC events
decorator.datasource.p6spy.enable-logging=true
decorator.datasource.datasource-proxy.query.log-level=debug
decorator.datasource.datasource-proxy.slow-query.enable-logging=true
decorator.datasource.datasource-proxy.slow-query.log-level=warn
decorator.datasource.datasource-proxy.slow-query.logger-name=
# Use com.p6spy.engine.spy.appender.MultiLineFormat instead of com.p6spy.engine.spy.appender.SingleLineFormat
decorator.datasource.p6spy.multiline=true
# Use logging for default listeners [slf4j, sysout, file]
decorator.datasource.p6spy.logging=slf4j
# Log file to use (only with logging=file)
decorator.datasource.p6spy.log-file=spy.log
# Custom log format, if specified com.p6spy.engine.spy.appender.CustomLineFormat will be used with this log format
decorator.datasource.p6spy.log-format=
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.5.8</version>
</dependency>
but getting only empty output from p6spy:
2019-12-24 16:22:13.103 DEBUG 11672 --- [ntainer#0-0-C-1] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL query
2019-12-24 16:22:13.103 DEBUG 11672 --- [ntainer#0-0-C-1] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [SELECT COMIT_ID FROM DPL_PARTY.USR_DTL WHERE INDVDL_ID = (SELECT INDVDL_ID FROM DPL_PARTY.INDVDL_TLCMMNCTN WHERE EML_VAL = ?)]
2019-12-24 16:22:13.181 INFO 11672 --- [ntainer#0-0-C-1] p6spy :
2019-12-24 16:22:13.182 DEBUG 11672 --- [ntainer#0-0-C-1] c.s.a.repository.UserRepository : Obtained comitId=XBBKRHL for email of niren.sinha#bnymellon.com from the DB.
2019-12-24 16:22:13.286 INFO 11672 --- [ntainer#0-0-C-1] p6spy :
The query themselves execute fine. What am I missing here? Thanks.
Try to leave out the empty configuration for the log format:
# Custom log format, if specified com.p6spy.engine.spy.appender.CustomLineFormat will be used with this log format
# decorator.datasource.p6spy.log-format=
I think if you have the property without a value, it will be passed as an empty string.

Spring Neo4j Transaction Rollback doesn't work

I'm using spring neo4j (version 3.3.4) and trying to use spring neo4j transactions. I configured it as Spring neo4j configurations. Everything was fine, but the rollback cannot work.
For example, I tried to add one new node and and one existing node in one transaction. It raised a RuntimeException and should rollback. But the first node is created without rolling back in the database. The log shows that rolling back has happened. Does anyone had the same problem or know how to figure it out? Thanks in advance.
The log is as follows:
[2018-08-14 17:48:20.845][http-nio-8888-exec-4] DEBUG o.s.d.n.t.Neo4jTransactionManager - Rolling back Neo4j transaction [org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction#421cb02f] on Session [org.neo4j.ogm.session.Neo4jSession#2f8c5762]
[2018-08-14 17:48:20.845][http-nio-8888-exec-4] DEBUG o.n.o.d.b.t.BoltTransaction - Rolling back native transaction: org.neo4j.driver.internal.ExplicitTransaction#5e10b6b3
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.neo4j.ogm.transaction.Transaction - Thread 54: Rollback transaction extent: 0
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.neo4j.ogm.transaction.Transaction - Thread 54: Rolled back
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.neo4j.ogm.transaction.Transaction - Thread 54: Close transaction extent: 0
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.neo4j.ogm.transaction.Transaction - Thread 54: Closing transaction
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.s.d.n.t.Neo4jTransactionManager - Closing Neo4j Session [org.neo4j.ogm.session.Neo4jSession#2f8c5762] after transaction
[2018-08-14 17:48:20.846][http-nio-8888-exec-4] DEBUG o.s.d.n.t.Neo4jTransactionManager - Resuming suspended transaction after completion of inner transaction
[2018-08-14 17:48:20.848][http-nio-8888-exec-4] ERROR c.s.k.c.s.i.GraphOperationServiceImpl - Error in committing directives: Node(19354) already exists with label `Product` and property `prodName` = 'test1'
org.neo4j.driver.v1.exceptions.ClientException: Node(19354) already exists with label `Product` and property `prodName` = 'test1'
[2018-08-14 17:48:20.849][http-nio-8888-exec-4] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction rollback
[2018-08-14 17:48:20.849][http-nio-8888-exec-4] DEBUG o.s.j.d.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [HikariProxyConnection#1121924585 wrapping com.mysql.jdbc.JDBC4Connection#41813449]
[2018-08-14 17:48:20.850][http-nio-8888-exec-4] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [HikariProxyConnection#1121924585 wrapping com.mysql.jdbc.JDBC4Connection#41813449] after transaction
[2018-08-14 17:48:20.850][http-nio-8888-exec-4] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
It is solved. I post this answer in case someone else has the same problem.
The problem is that Rolling back JDBC transaction is on a mysql jdbc connection instead of using neo4j transaction manager, which is indicated by the following log. It happens only during rolling back the neo4j transaction with no error.
[2018-08-14 17:48:20.849][http-nio-8888-exec-4] DEBUG o.s.j.d.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [HikariProxyConnection#1121924585 wrapping com.mysql.jdbc.JDBC4Connection#41813449]
The solution is to specify a bean name for neo4jTransactionManager instead of the default name "transactionManager", so that it won't be confusing with the default mysql transaction manager. And then specify the transaction manager in the transactional annotator e.g. #transactional("neo4jTransactionManager").

Record inserted but still not found

I was currently using java spring jdbctemplate to insert and select record. However, Now the system have go for production, some issue has happen. This system will prevent record duplicate by select the record by certain key to check is it already exist. However, I notice the 1st transaction after inserted into database, then the 2nd transaction come in, jdbc template select still show that record was not found? I notice this will happen if the 2 transaction was submitted within a milliseconds different...
The record time was
e.g.
1st Record insert - 15/6/17 12:22:39,986 - insert success
2nd record select - 15/6/17 12:22:44,680 - search record show not found?
Sample insert log
15/6/17 12:22:39,937 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:869) Executing prepared SQL update
15/6/17 12:22:39,938 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:616) Executing prepared SQL statement [INSERT INTO ...;]
15/6/17 12:22:39,950 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:879) SQL update affected 1 rows
15/6/17 12:22:39,951 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:869) Executing prepared SQL update
15/6/17 12:22:39,952 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:616) Executing prepared SQL statement [INSERT INTO ...;]
15/6/17 12:22:39,965 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.core.JdbcTemplate:879) SQL update affected 1 row
15/6/17 12:22:39,970 DEBUG [30:http-nio-8080-exec-2] (org.springframework.jdbc.datasource.DataSourceUtils:327) Returning JDBC Connection to DataSource
Sample select log
15/6/17 12:22:44,680 DEBUG [29:http-nio-8080-exec-1] (org.springframework.jdbc.core.JdbcTemplate:682) Executing prepared SQL query
15/6/17 12:22:44,680 DEBUG [29:http-nio-8080-exec-1] (org.springframework.jdbc.core.JdbcTemplate:616) Executing prepared SQL statement [SELECT * FROM ...]
Please note that this system was set in 2 different server by using load balancing. They both point to the same database. The insert was completed on server 1 because it already return the connection to the jdbc connection pool. A new transaction come in the server 2, select but no record found?
I wonder why it still cannot found event after insert was finish? Is it because of the time delay?
This question had been resolved. It was due to the server time not consistent. Thanks
RealSkeptic

How to reconnect database if the connection closed in spring jpa?

I am using spring-boot, spring-jpa, mysql in my web application.When my application is running for some hours, I always got below exceptions:
2016-07-30 21:27:12.434 ERROR 13553 --- [http-nio-8090-exec-8] o.h.engine.jdbc.spi.SqlExceptionHelper : No operations allowed after connection closed.
2016-07-30 21:27:12.434 WARN 13553 --- [http-nio-8090-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08003
2016-07-30 21:27:12.434 ERROR 13553 --- [http-nio-8090-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper : No operations allowed after connection closed.
2016-07-30 21:27:12.438 ERROR 13553 --- [http-nio-8090-exec-8] [.[.[.[.c.c.Go2NurseJerseyConfiguration] : Servlet.service() for servlet [com.cooltoo.config.Go2NurseJerseyConfiguration] in context with path [] threw exception [org.springframework.dao.DataAccessResourceFailureException: could not prepare statement; nested exception is org.hibernate.exception.JDBCConnectionException: could not prepare statement] with root cause
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3119) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3570) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3559) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4110) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155) ~[mysql-connector-java-5.1.25.jar!/:na]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322) ~[mysql-connector-java-5.1.25.jar!/:na]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
I have checked that the database is running well. I have to restart my spring-boot application when that happened. How can I check what the problem is? Why the database connection got closed? If that happened, whether I can re-connect the database?
Below is my application.properties:
spring.datasource.url=jdbc:mysql://192.168.99.100:3306/test?characterEncoding=utf8
spring.datasource.username=admin
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.max-active=150
This seems like a common error with MySQL.
1) Add this to your application.properties and see how it goes:
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
testOnBorrow is detailed in the spring doc and this other stackoverflow question. I'm however unable to find a reference on validationQuery in Spring's doc, but it seems to do the trick.
2) Or, you may use testWhileIdle as suggested here http://christoph-burmeister.eu/?p=2849
He suggests adding this to your application.properties:
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
This solution is also mentionned in the other stackoverflow question, it was just not the accepted answer, but seems to be the solution for some.
3) In this case, they also added timeBetweenEvictionRunsMillis:
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis = 3600000
EDIT: Another stackoverflow question that covers this (with a very complete answer)

How do I get myBatis update statement to commit in a Java Spring application?

I have Java Spring application running in a jetty-maven plugin. When I call a myBatis insert statement, the statement is automatically committed. However, when I call update, the statement is not committed. Per the myBatis documentation (http://www.mybatis.org/spring/transactions.html):
You cannot call SqlSession.commit(), SqlSession.rollback() or SqlSession.close() over a Spring managed SqlSession.
How do I configure my application to auto commit on a myBatis update statement?
I enabled logging. Here is what the log states on updates:
2012-12-12 17:20:31,669 DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
2012-12-12 17:20:31,669 DEBUG [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#19e86f9] was not registered for synchronization because synchronization is not active
2012-12-12 17:20:31,669 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
2012-12-12 17:20:31,669 DEBUG [org.springframework.jdbc.datasource.DriverManagerDataSource] - Creating new JDBC DriverManager Connection to [jdbc:jtds:sqlserver://test/test]
2012-12-12 17:20:31,684 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [net.sourceforge.jtds.jdbc.ConnectionJDBC3#af7eaf] will not be managed by Spring
2012-12-12 17:20:31,684 DEBUG [com.persistence.MyMapper.updateMyItem] - ooo Using Connection [net.sourceforge.jtds.jdbc.ConnectionJDBC3#af7eaf]
2012-12-12 17:20:31,684 DEBUG [com.persistence.MyMapper.updateMyItem] - ==> Preparing: update myTable set date=? where id=?
2012-12-12 17:20:31,700 DEBUG [com.persistence.MyMapper.updateMyItem] - ==> Parameters: 2012-11-26 00:00:00.0(Timestamp), 0(Integer)
2012-12-12 17:20:31,700 DEBUG [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#19e86f9]
2012-12-12 17:20:31,700 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
On insert, the log is:
2012-12-12 16:35:53,932 DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
2012-12-12 16:35:53,932 DEBUG [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#22da8f] was not registered for synchronization because synchronization is not active
2012-12-12 16:35:53,932 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
2012-12-12 16:35:53,932 DEBUG [org.springframework.jdbc.datasource.DriverManagerDataSource] - Creating new JDBC DriverManager Connection to [jdbc:jtds:sqlserver://test/test]
2012-12-12 16:35:53,932 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [net.sourceforge.jtds.jdbc.ConnectionJDBC3#3af3cb] will not be managed by Spring
2012-12-12 16:35:53,932 DEBUG [com..persistence.MyMapper.insertMyItem] - ooo Using Connection [net.sourceforge.jtds.jdbc.ConnectionJDBC3#3af3cb]
2012-12-12 16:35:53,932 DEBUG [com.persistence.MyMapper.insertMyItem] - ==> Preparing: insert into myTable (id,date) values (?, ?)
2012-12-12 16:35:53,932 DEBUG [com.persistence.MyMapper.insertMyItem] - ==> Parameters: 5(Integer), 2012-11-26 00:00:00.0(Timestamp)
2012-12-12 16:35:53,932 DEBUG [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#22da8f]
2012-12-12 16:35:53,932 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
The insert and update log statements seem to indicate the same basic steps.
After a bit more research, I found that it was a client issue. It was always passing a 0 for the id in the update statement. The records have ids > 0. Along the way, I configured spring txn management. It was at that point that I observed the same behavior and realized it must be something other than server side configuration issue. Sorry about not catching that prior to posting.

Categories