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

Update Record 

The following example shows updating a student record into DB. The parameterClass attribute allows us to pass the student record to be updated as parameter to the query.

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

File Name  :  
com/bethecoder/tutorials/ibatis/tests/basic/Update.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 Update {

  /**
   @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.setHobby("My new hobby");
    sqlMapClent.update("Student.updateHobby", stud);
    System.out.println(stud + " record updated successfully..");
    
    stud = (StudentsqlMapClent.queryForObject("Student.getById"1);
    System.out.println(stud);
  }
}
   

It gives the following output,
Student[1, Jim, Attic, 32, Painting, +919999999999]
Student[1, Jim, Attic, 32, My new hobby, +919999999999] record updated successfully..
Student[1, Jim, Attic, 32, My new hobby, +919999999999]



 
  


  
bl  br