Tutorial on Ibatis-Using Eclipse Ibator plugin to generate Persistence POJO Models, SqlMap and DAO :: with coverage of Dynamic SQL and working downloadable example

IBatis is a lightweight persistence framework that maps objects to SQL statements. The SQL is decoupled from the application logic by storing in XML descriptor file . SQL mapping is done by data mapper to persist objects to a relational database. 
In this article i am going to discuss on how to use ibator plugin in eclipse to generate Java model objects from your database, the DAO interface and its auto implementation to access your db and auto generated SQL map xml files. And also we will deal with fun of dynamic SQL.  The Link for downloading the working eclipse project is given at the end of article. For more detail about ibatis visit the references at last of this article.

Part A: Ibator/DB Configuration
Step 1. Installing IBator
Visit this link and download ibator plugin for eclipse


Or From Eclipse Update Site :

Step 2. Requirements and Project Configuration: 

EasyJFrame : Reusable JFrame class

Here, i am going to describe a reusable jFrame class, which can be used as substitute of standard console output.

Resuable JFrame CODE:

Java-Opening a URL in default browser with start utility in windows

Java-Opening a URL in default browser with start utility in windows
String cmd = "cmd.exe /c start ";
String file = "http://www.google.com";
Runtime.getRuntime().exec(cmd + file);

Dependency Injection with Java Spring IoC, A Complete Example

Here i am going to describe a simple example of Dependency Injection which uses Spring IoC framework.
You may refer to my earlier"Understanding Dependency Injection and Its Importance" for understanding the concepts.
This example uses Implementation of  Operation, Reader and Writer Interfaces.
We simply perform a one of the arithmentic Operation by taking values from Reader and write the values using Writer Class.

Reader Interface:
public interface Reader {
    Operands readValues(String promptMsg);

Its implementations can be:
public class ConsoleReader implements Reader{
    Operands oprnds;
    Scanner sc;
    public ConsoleReader (){
        oprnds=new Operands();
        sc=new Scanner(System.in);
    public Operands readValues(String promptMsg) {
        return oprnds;

The Operation Interface
public interface Operation {
    Result operate(long op1,long op2);
    String getOperationName();

The Operation Interface can have implementations such as
public class Multiply implements Operation {
    Result res;
    public Multiply(){
          res=new Result();
    public Result operate(long op1, long op2) {
        return res;
    public String getOperationName() {
        return "Multiply";

public class Add implements Operation {
    Result res;
    public Add(){
        res=new Result();
    public Result operate(long op1, long op2) {
        return res;
    public String getOperationName() {
        return "Add";

The  writer Interface
public interface Writer {
    void write(Result res);

Its ConsoleWriter Implementation
public class ConsoleWriter implements Writer{
 public void write(Result res)
  System.out.println("The result after operation : "+res.getRes());

Its TXTFileWriter Implementation
public class TXTFileWriter implements Writer{
    File file;
    PrintWriter fwriter;
    public TXTFileWriter(){
        try {
           file = new File("output.txt");
           fwriter = new PrintWriter( new BufferedWriter( new FileWriter(file)));
       } catch (Exception ex) {
    public void write(Result res)

The Model Classes
public class Operands {
    private long op1;
    private long op2;
//setters and getters

The Result Class
public class Result {
    private long res;
    //setters and getters

Now create a configuration file in class path i.e, src folder of project directory - confBean.xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<bean id="operation" class="com.gt.spring.operation.Add"/>
<bean id="reader" class="com.gt.spring.reader.ConsoleReader"/>
<bean id="writer" class="com.gt.spring.writer.ConsoleWriter"/>

The dependency injection will help you to inject the implementations of an object at runtime.
In the Main Class: read the xml file and inject the dependent beans…
public class Main {
    public static void main(String[] args) {
    ApplicationContext ctx = 
new ClassPathXmlApplicationContext("confBean.xml");
        //get beans from ctx
        Reader rdr = (Reader) ctx.getBean("reader");
        Operation opr = (Operation)ctx.getBean("operation");
        Writer wrt = (Writer) ctx.getBean("writer");//
        //read operands
        Operands opnds = rdr.readValues("Enter the Values :");
        //do operation
        Result res =opr.operate(opnds.getOp1(), opnds.getOp2());
        //write result

The Complete Code is Available to Download from My 4Shared Share.