| By Walid El Sayed Aly | Article Rating: |
|
| June 25, 2011 11:00 AM EDT | Reads: |
1,539 |
I recently used the framework by Craftsman Spy and must say it was really exciting. This framework is very useful for JDBC logging.
Craftsman Spy is an open source and free framework for JDBC logging. It is a JDBC driver implementation. You can download it from http://zer0.free.fr/craftsman/spy.php, and you can also bind it in your local repository for Maven. But how does it work? I will explain it in my next article.
What are the benefits of Craftsman Spy?
Spy logger logs all SQL processing and connections with executing spent time, all stored procedures with arguments, all batch processing and result sets. Craftsman Spy Framework is very helpful for all JUnitTests because you see what runs under the roof and all hidden processes. Unfortunately, you cannot find all these facilities in the Spring JDBC Framework.
How does Spring JDBC work without the Spy framework?
You can use the standard JDBC template from Spring like the following configuration that I took 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>
Now you work with the data source, e.g.:
public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
}
How does Spring JDBC work with the Spy framework?
It is rather simple to bind the Craftsman Spy and the Spring JDBC frameworks together. You only have to bind the downloaded SPY jars from http://zer0.free.fr/craftsman/spy.php or you use Maven to get the jars from your local repository. Secondly, you only change the Spring JDBC configuration:
- Change the name of the DriverClassName to craftsman.spy.SpyDriver.
- Also change the URL to activate the Spy framework.
Just 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 this was a useful piece of advice for you.
Published June 25, 2011 Reads 1,539
Copyright © 2011 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Walid El Sayed Aly
Walid El Sayed Aly is originally from the land of the pyramids and pharaohs and is now living and working in Germany. He is a software developer whose passion is Java. His philosophy: think like a man of action, act like a man of thought.
- The History of Programming
- Cloud Expo Silicon Valley Call for Papers Deadline August 12
- Rethink SOA - A Recipe for Business Transformation
- It's the Java vs. C++ Shootout Revisited!
- Valve, JAAS and Filter in Tomcat
- Externalizing Fine-Grained Authorization from Applications
- ActiveJDBC: New Java ORM
- After Five-Year Drought, Java SE7 Is Here
- Oracle Wants $2.6 Billion in Damages from Google
- Google Waves Small White Flag
- Start-up Betas Java PaaS for the Federated Cloud
- Oracle Reportedly Asking Android Makers for Royalties
- Driving Java Innovation in the Cloud at Cloud Expo 2011 New York
- The History of Programming
- Cloud Expo Silicon Valley Call for Papers Deadline August 12
- Rethink SOA - A Recipe for Business Transformation
- Sun Burns Oracle
- It's the Java vs. C++ Shootout Revisited!
- Sun Settles Eolas’ Java Claims
- Valve, JAAS and Filter in Tomcat
- Oracle Wants Billions from Google Suit
- Three Tips to Successfully Load Test Adobe Flex Applications
- Developers Should Learn Why, Not Just Memorize What
- Oracle to Dump OpenOffice.org on Apache
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- JavaServer Faces (JSF) vs Struts
- The i-Technology Right Stuff
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- What's New in Eclipse?
- i-Technology Predictions for 2007: Where's It All Headed?






























