Skip to main content

Steps to log SQL queries in Java/Tomcat app when using SQL Server using log4JDBC & Spylog

SQL server does not support logging queries, but this feature is available in MySQL and PostGREs

We have to follow the steps below to enable logging in SQL Server based tomcat/java application.

1. Download the necessary jar files. (choose whichever version is latest)

      1. log4jdbc4-1.2.jar
      2. log4j-over-slf4j-1.7.7.jar
      3. log4j-1.2.16.jar

2. Place them in the lib folder and make sure they are added in class path.

3. Place log4j.properties in the lib folder as well and include it in class path.

4. configure the location where the log file must be written with respect to the deployed folder.

log4j.appender.Log4JDBC.File=../logs/sql.log

5. Modify the database_params file or any other database config file and make changes to the jdbc url and driver class name as follows. (sample attached)




drivername=net.sf.log4jdbc.DriverSpy

url=jdbc:log4jdbc:jtds:sqlserver://hostname:1433;databasename=dbname;useLOBs=false;

6. Restart the application for the changes to take effect. all the queries which pass through the jdbc driver will get printed in the sql.log as mentioned in the log4j.properties

Comments

Popular posts from this blog

Tobi is not Madara Uchiha and that is my verdict.

1. Zetsu’s Approach Zetsu keeps the name Tobi and he is the only person who is very close to Tobi, since he is a spy and has the most information in the entire Naruto universe, he exists everywhere planted beforehand blended with the environment. Zetsu also wonders how much Kabuto knows about them, in vary tone. They’ve got something to hide other than their fighting powers. Kabuto already knows most of their secrets which they’ve got hidden even from Akatsuki members to avoid an internal clash for power. 2. Tobi’s awe of Kabuto’s Re-animation. Okay, this is very very intriguing. Madara Uchiha is afraid of something; it’s also a very best kept secret. since Kabuto promises that he hasn't told a soul. Madara who can analyze and formulate any jutsu asks “how did you do this?” Who is he afraid of, let us think back, He is not afraid of anyone. He has had only reverence for Hashirama, even then it cannot be first or the second Hokages since they were sealed by the third H...

Working!! is fun and satisfying

Working!! is an anime about the interesting things that happen in a family restaurant called Wagnaria, primarily about the staff that work there. Every character is quirky in someway or the other and it makes for some good comedy and drama. I’d like to go over the characters in the series in the order of their importance and talk about how I feel about them. Taneshima Popura: Taneshima is a high school senior who is very short, she is confused for an elementary student most of the time.  She is very upbeat and works hard, but has a huge complex about her height and is sometimes pranked upon by fellow workers in Wagnaria. Takanashi Souta: Takanashi is a junior to Taneshima and is recruited by her to work in Wagnaria at the start of the series. He likes all things tiny and deeply adores Taneshima.  He is level headed most of the time and works hard. He has three elder sisters and one younger sister whom he has to ...

Recently executed queries in SQL Server

To find out what all queries were executed recently in a sql server database, use the following queries Specific database: SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.* FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest WHERE dest.dbid = DB_ID(' msdb ') ORDER BY deqs.last_execution_time DESC   All Databases: SELECT deqs.last_execution_time AS [Time], dest.text AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest ORDER BY deqs.last_execution_time DESC