tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 iBATIS > Basics > Get By Id

Get By Id 

The following example shows getting a particular record from table given the record id. The attribute parameterClass="int" allows us to pass student id as parameter which would substitute #value# in the SQL.

File Name  :  
/IBATIS001/config/basic/GetById.xml 

File Name  :  
com/bethecoder/tutorials/ibatis/tests/basic/GetById.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.ibatis.tests.basic;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;

import com.bethecoder.tutorials.ibatis.common.Student;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class GetById {

  /**
   @param args
   @throws IOException 
   @throws SQLException 
   */
  public static void main(String[] argsthrows IOException, SQLException {

    Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
    SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient(reader);

    Student stud = (StudentsqlMapClent.queryForObject("Student.getById"1);
    System.out.println(stud);
    
    stud = (StudentsqlMapClent.queryForObject("Student.getById"2);
    System.out.println(stud);
  }
}
   

It gives the following output,
Student[1, Jim, Attic, 32, Painting, +919999999999]
Student[2, Raj, Kumar, 18, Reading books, +914444488888]



 
  


  
bl  br