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

Create Record 

The following example shows inserting a student record into DB. The selectKey tag allows us to generate a primary key. Depending upon the database and primary key generation strategy the selectKey tag has to be specified before or after the insert query.

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

File Name  :  
com/bethecoder/tutorials/ibatis/tests/basic/Insert.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
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 Insert {

  /**
   @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 student = new Student("Sriram""Kasireddi"(short)1"+919999999999""Boxing");
    sqlMapClent.insert("Student.insert", student);
    
    System.out.println(student + " record created successfully..");
  }
}
   

It gives the following output,
Student[6, Sriram, Kasireddi, 1, Boxing, +919999999999] record created successfully..


                    Print

   



Books Recommendation

 
 
bl  br