How to use JDBC and transactions in Spring with BTM
This howto is intended for developers using Spring wanting to take advantage of distributed transactions when using JDBC code.
Spring and BTM versions used in this document:
- Spring 2.x
- BTM 1.0
Database used for this document:
- Derby version 10.2.2.0
JDK version
- This requires JDK 1.5+
Project directory structure
Here are the folders you first need to create:
Below is a list of required jars. You have to copy them under the lib/ folder:
- spring.jar
- cglib-nodep-2.1_3.jar
- btm-1.0.jar
- commons-logging-1.0.4.jar
- slf4j-jdk14.jar
- geronimo-spec-jta-1.0.1B-rc4.jar
- derby-10.2.2.0.jar
- derbytools-10.2.2.0.jar
Derby configuration
Ensure that you strictly follow these instructions as variations can cause problems.
You need to create two databases, each one with a single users table.
Create the file PROJECT_HOME/derby-create.sql with this content:
Then run this command:
Configuring Spring
beans.xml configuration
Create a file named beans.xml in the PROJECT_HOME/ folder with this content:
Test Code
Create these Java classes in the PROJECT_HOME/src/jtatest folder. Note: this code isn't anywhere near production ready - it's only supposed to be used as a simple test !
Now you have to run those commands from the PROJECT_HOME/ folder.
Compile these classes using this command line:
Lastly, run your application using this command line: