Delete Record
The following example shows deleting a student record from DB.
The parameterClass attribute allows us to
pass student record id as parameter to the query.
package com.bethecoder.tutorials.ibatis.tests.basic;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class Delete {
/**
* @param args
* @throws IOException
* @throws SQLException
*/
public static void main ( String [] args ) throws IOException, SQLException {
Reader reader = Resources.getResourceAsReader ( "SqlMapConfig.xml" ) ;
SqlMapClient sqlMapClent = SqlMapClientBuilder.buildSqlMapClient ( reader ) ;
sqlMapClent.delete ( "Student.deleteById" , 1 ) ;
System.out.println ( "Student record deleted successfully.." ) ;
}
}
It gives the following output,
Student record deleted successfully..