Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Based on the sampleConnection example, the method of integrating with ALTIBASE in Altibasein iBATIS is explained in detail.

...

  1. Click Menu-File-Java Project

  2. Project name: Enter SimpleConnection

  3. Click the Finish button

Image RemovedImage Added

Creating SqlMap File

...

  1. Right-click on the SimpleConnection project-src directory and click New-File.

  2. Create Person.xml in File name:.

Image RemovedImage Added
Write the following in the Person.xml file.

...

  1. Create a properties file (db.properties) that defines properties for ALTIBASE Altibase connection. (Right-click on SimpleConnection project-src directory and click New-File. Create db.properties in File name :)

 

Code Block
driver=Altibase.jdbc.driver.AltibaseDriver
url=jdbc:Altibase://192.168.1.35:21129/mydb
username=sys
password=manager

2. Set the dataSource and SqlMap files for interworking with ALTIBASE Altibase in the SqlMapConfig file (SqlMapConfigExample.xml). (Right-click on the SimpleConnection project-src directory and click New-File. Create SqlMapConfigExample.xml in File name:)

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
 
<sqlMapConfig>
 
<properties resource="db.properties" />
 
<transactionManager type="JDBC" >
    <dataSource type="SIMPLE">
       <property name="JDBC.Driver" value="${driver}"/>
       <property name="JDBC.ConnectionURL" value="${url}"/>
       <property name="JDBC.Username" value="${username}"/>
       <property name="JDBC.Password" value="${password}"/>
    </dataSource>
</transactionManager>
 
<sqlMap resource="Person.xml" />
 
</sqlMapConfig>

Creating Application

  1. Create a Person class (Person.java) that is a DO object for the person table.

  2. Right-click in the src directory of the SimpleConnection project and click New-Class.

  3. Enter examples.domain in Package: and Person in Name:

Image RemovedImage Added

 

Write the following in the Person.java file.

Code Block
package examples.domain;
import java.sql.*;
public class Person {
    private int id;
    private String name;
    private Date birthDate;
    private double weightInKilograms;
    private double heightInMeters;
    public int getId () {
        return id;
    }
    public void setId (int id) {
        this.id = id;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }
    public Date getBirthDate() {
        return birthDate;
    }
    public void setWeightInKilograms(double weightInKilograms) {
        this.weightInKilograms = weightInKilograms;
    }
    public double getWeightInKilograms() {
        return weightInKilograms;
    }
    public void setHeightInMeters(double heightInMeters) {
        this.heightInMeters = heightInMeters;
    }
    public double getHeightInMeters() {
        return heightInMeters;
    }
    public String toString(){
                return "id="+id+", name="+name+", birthData="+birthDate+",
weightInKillograms="+weightInKilograms+
",heightInMeters="+heightInMeters;
    }
}

3. Write a main program (PersonApp.java) that executes CRUD in the DB.

4. Right-click in the src directory of the SimpleConnection project and click New-Class.

 5. Enter PersonApp in Name :.

Image RemovedImage Added

 

Write the following in the PersonApp.java file.

Code Block
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
import examples.domain.Person;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
 
public class PersonApp {
 
public static void main(String[] args) throws Exception {
    String resource ="SqlMapConfigExample.xml";
    Reader reader = Resources.getResourceAsReader(resource);
    SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
 
    //insert Person
    Person newPerson1 = new Person();
    newPerson1.setName("KIM");
    newPerson1.setBirthDate (new java.sql.Date(1978,1-1,1));
    newPerson1.setHeightInMeters(1.82);
    newPerson1.setWeightInKilograms(80.23);
    sqlMap.insert ("insertPerson", newPerson1);
 
    Person newPerson2 = new Person();
    newPerson2.setName("LEE");
    newPerson2.setBirthDate (new java.sql.Date(1975,5-1,5));
    newPerson2.setHeightInMeters(1.57);
    newPerson2.setWeightInKilograms(45.23);
    sqlMap.insert ("insertPerson", newPerson2);
    System.out.println();
    System.out.println("insert Person");
 
    List<Person> list = (List<Person>)sqlMap.queryForList("getAllPersons");
    System.out.println("Selected "+list.size()+" records.");
    for(int i=0; i< list.size();i++){
        System.out.println(list.get(i));
    }
 
    //update Person
    newPerson1.setHeightInMeters(1.93);
    newPerson1.setWeightInKilograms(86.36);
    sqlMap.update("updatePerson", newPerson1);
    System.out.println();
    System.out.println("update Person");
    list = sqlMap.queryForList("getAllPersons");
    System.out.println("Selected "+list.size()+" records.");
    for(int i=0; i< list.size();i++){
        System.out.println(list.get(i).toString());
    }
    System.out.println();
    System.out.println("get Person");
 
    //get Person
    Integer personPk = new Integer(1);
    Person person = (Person) sqlMap.queryForObject ("getPerson", personPk);
    System.out.println(person);
 
    //delete Person
    sqlMap.delete ("deletePerson", new Integer(1));
    sqlMap.delete ("deletePerson", new Integer(2));
    System.out.println();
    System.out.println("delete Person");
    list = sqlMap.queryForList("getAllPersons");
    System.out.println("Selected "+list.size()+" records.");
    for(int i=0; i< list.size();i++){
        System.out.println(list.get(i));
    }
 
}
}

Adding Related JAR Files

Add the Altibase.jar and ibatis-2.3.4.x.jar files.

Right-click on SimpleConnection project, click Properties-Java Build Path-Click Add External JARS in Libraries to add Altibase.jar and ibatis-2.3.4.x.jar files.

Image RemovedImage Added

Running Application

Run the SimpleConnection project.

After clicking the SimpleConnection project, run from the menu or click the Run button.

 

 

 

...