tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 iBATIS > Advanced > Get records by Ids in

Get records by Ids in 

The following example shows getting a list of student records given their ids. The attribute parameterClass="list" allows us to pass list of student ids as parameter to the query which would substitute #value[]# in the SQL. The iterate tag builds a comma separated list of student ids to construct the where in clause of SQL.

File Name  :  

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

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

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 GetByIdIn {

   @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);

    List<Integer> studentIds = Arrays.asList(124);
    List<Student> studs = (List<Student>
      sqlMapClent.queryForList("Student.getByIdsIn", studentIds);

    for (Student stud : studs) {

It gives the following output,
Student[1, Jim, Attic, 32, Painting, +919999999999]
Student[2, Raj, Kumar, 18, Reading books, +914444488888]
Student[4, Arjun, Mishra, 28, Football, +917777777777]


bl  br