0

How to use P6Spy in a simple JDBC Application

Background

This article demonstrates how to use P6Spy in a simple JDBC application

Software Environment

  • Windows 7 Professional SP1
  • Eclipse – Kepler Release
  • Java 1.7 (1.7.0_67 – Windows x86)
  • MySQL 5.6.16 – Community Server (GPL)
  • MySQL Java Connector 5.1.34
    • Referenced mysql-connector-java-5.1.34-bin.jar in Eclipse
  • P6Spy 2.1.2
    • Download from https://github.com/p6spy/p6spy/releases
    • Referenced p6spy-2.1.2.jar in Eclipse
  • SLF4J 1.7.7
    • Referenced the following in Eclipse
      • slf4j-api-1.7.7.jar
      • slf4j-log4j12-1.7.7.jar
      • slf4j-simple-1.7.7.jar
  • Log4j2 2.0.2
    • Reference the following in Eclipse
      • log4j-core-2.0.2.jar
      • log4j-api-2.0.2.jar
      • log4j-1.2-api-2.1.jar (Yes, it is in 2.0.2 release)

Data Set Up

log4j2.xml

spy.properties

Java Codes

Eclipse Workspace

turretadotcom_p6spy_wm

Sample Output

When you run MySqlJdbcSample.java within Eclipse, the logs are written in logs/name.log file. Based on the log4j2.xml, the file is rotated once the size of 1 MB is reached. Here is a sample output:

Download the Project

https://www.dropbox.com/s/24nbtz3jd3cc4zu/turreta_p6spy.zip?dl=0