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

Get All Records 

The following example shows getting all records from a particular table. Note that alias names provided in the SQL query matches with property names in result class POJO. iBatis invokes appropriate setter method based on alias names. This POJO should have a no argument default constructor so that iBatis creates an instance and sets mapped properties.

We have used Student.getAll string to query all students, where Student is the query namespace and getAll is the actual query id. There can be N number of queries in a single namespace.

File Name  :  

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

import java.sql.SQLException;
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 GetAll {

   @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 <Student> studs = (List<Student>sqlMapClent.queryForList("Student.getAll");

    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[3, Ram, Prasad, 24, Painting, +918888888888]
Student[4, Arjun, Mishra, 28, Football, +917777777777]
Student[5, Vishal, Pratap, 19, Cricket, +91666666666]


bl  br