DZone
Performance Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Performance Zone > Logging with Spring JDBC and Craftsman Spy

Logging with Spring JDBC and Craftsman Spy

Walid El Sayed Aly user avatar by
Walid El Sayed Aly
·
Jun. 17, 12 · Performance Zone · Interview
Like (1)
Save
Tweet
13.29K Views

Join the DZone community and get the full member experience.

Join For Free

It was very interesting when I used the framework from Craftsman. This Framework is very useful for the JDBC Logging.

Craftsman Spy is an open source and free framework for JDBC logging, it’s a JDBC driver implementation, you can download it from http://zer0.free.fr/craftsman/spy.php, and also you bind it in your local-Repository for Maven: how it’s work? I will explain it in my next article.

What are the benefits of craftsman Spy?

Spy logger logs all SQL connection and processing’s with executing spent time, all the stored procedures with arguments, all the batch processing’s and the result sets.  Craftsman SPY Framework is very helpful for all JunitTests, because you see which runs under the roof and all hidden processes.  You can’t find all this facilities in the Spring JDBC Framework, Pity!

How Spring-JDBC works without Spy framework?

You can use the standard JDBCTemplate from Spring like following configuration, which I took it from Spring Data access with JDBC:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="corporateEventDao" class="com.example.JdbcCorporateEventDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="jdbc.properties"/> 
</beans> 

 

 And now you can work the Data source like this:

public class JdbcCorporateEventDao implements CorporateEventDao {
   private JdbcTemplate jdbcTemplate;
   public void setDataSource(DataSource dataSource) {
       this.jdbcTemplate = new JdbcTemplate(dataSource);
   } }


How Spring-JDBC works with Spy framework

It’s very easy to bind the Craftsman Spy and the Spring JDBC framework.  You must only  bind the download SPY Jar’s from http://zer0.free.fr/craftsman/spy.php or use Maven to get the Jars from your local repository. Second you must only change the Spring-JDBC Configuration:

  1. Change the name of the  driverClassName to craftsman.spy.SpyDriver
  2. And you must also change the url to able Spy framework

Like that:

Before:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/></bean> 

After:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="craftsman.spy.SpyDriver"
<property name="url" value="jdbc:spy:mysql://server.com:5000/database"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/> </bean>

 

I hope it was a useful post. :) 

 

 

Spring Framework Framework

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Ultra-Fast Microservices: When Microstream Meets Wildfly
  • OpenTelemetry in Action: Identifying Database Dependencies
  • Maven Tutorial: Nice and Easy [Video]
  • Modern REST API Design Principles and Rules

Comments

Performance Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo