12/6/2023 0 Comments Log file spy![]() Copy spy.properties to project classpath: Copy spy.properties to your project root folder.All SQL statements will be logged into this file. Replace the realdriver with your existing MySQL JDBC driver realdriver=Ĭhange the logfile location in the logfile property. Modify P6Spy properties file: spy.properties.Original is MySQL JDBC driver –( ) Ĭhanged it to P6Spy JDBC driver ( .P6SpyDriver) You need to replace your existing JDBC driver with the P6Spy JDBC driver ( .P6SpyDriver) Modify P6Spy properties file: Modify your database configuration file. ![]() Add library dependency: Add p6spy.jar into your project library dependency.Extract it: Extract the p6spy-install.jar file, look for p6spy.jar and spy.properties.Download the P6Spy library: Get p6spy-install.jar.Here is simple tutorial to implement as well. Logging works but not exactly what you want and I wanted some time ago, but P6Spy does work perfectly. The datasource-proxy queries contain parameter values and you can even add custom JDBC statement interceptors so that you can catch N+1 query issues right from your integration tests. My logback.xml configuration file looks like the below: this outputs all SQL statements with parameters plus the resultset tables for all queries. #database.url=jdbc:log4jdbc:mysql://localhost:3306/db_name The driver and DB URLs then look like: =net.sf.ĭatabase.url=jdbc:log4jdbc:hsqldb:mem:db_name #Hsql ![]() Maven dependencies required for my setup are as below: Most recently I have now been using log4jdbc-log4j2 ( ) with SLF4j and logback. ![]() 16:21:22 4953 INFO jdbc.resultsettable - |ID |CREATED |DELETED |CODESET_ID |NAME |POSITION |PREFIX | insert into ENQUIRY_APPLICANT_DETAILS (ID, INCLUDED_IN_QUOTE, APPLICANT_ID, TERRITORY_ID, ENQUIRY_ID, ELIGIBLE_FOR_COVER) values (7, 1, 11, 1, 2, 0) Sample Output showing generated SQL with params in place together with result set table from query: 5. The latter also outputs a tabular representation of query results. One major convenience of this is that you can copy the SQL straight to your DB front-end and execute it as-is. Log4JDBC is a nice solution which prints the exact SQL going to the database with parameters in place, rather than the most popular answer here which does not do this. 18:01:15,088 | binding parameter as - MatchingStep 18:01:15,088 | binding parameter as - PRIVATE The output in your sql.log (example) then looks like this: 18:01:15,083 | update stepprovider set created_at=?, lastupdated_at=?, version=?, bundlelocation=?, category_id=?, customer_id=?, description=?, icon_file_id=?, name=?, shareStatus=?, spversion=?, status=?, title=?, type=?, num_used=? where id=? Just for convenience, here is the same configuration example for Logback (SLF4J)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |