Easy JDBC using Spring

Posted: February 7, 2012 in Java Posts, Random Posts

Nikos' Java blog

Spring has a well-written module for JDBC. We’ll use it to produce clean code for our application in 10 minutes.

The model

Our application handles information about persons. For every person there is interest about his name, age and a unique number (key).

In Java it’s a plain bean.

public class Person {
    private String name;
    private int age;
    private int id;
	
    // getters and setters
}

In the database it’s a simple table.

The persons table

To create it in MySQL you may refer to MySQL in 3 minutes.

Libraries

Download Apache Commons Logging from apache.org → 1.1.1.zip.

  • commons-logging-1.1.1.jar

Download Spring from springsource.com → Latest GA release → spring-framework-3.x.x.zip. The dist directory of this file contains the Spring 3 modules. We need the following jars:

  • jdbc-3
  • asm-3
  • core-3
  • beans-3
  • context-3
  • expression-3
  • transaction-3

Download MySQL JDBC driver from mysql.com → No…

View original post 888 more words

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s