Ibatis Tutorial – Sample Application Step 5

August 8th, 2008 by admin Leave a reply »

Step 5 : Create a standalone java class to run the application .


import java.io.Reader;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.model.Employee;

public class QueryEmployee {

public static void main(String[] args) {
try {
String resource = “SqlMapConfig.xml”;

Reader reader = Resources.getResourceAsReader(resource);
SqlMapClient sqlMap =
SqlMapClientBuilder.buildSqlMapClient(reader);
Integer employeePrimaryKey = new Integer(1);
Employee employee =
(Employee)sqlMap.queryForObject(“getEmployee”,
employeePrimaryKey);
System.out.println(employee.getFirstName()
+ “\t” + employee.getLastName());
}catch(Exception e) {
e.printStackTrace();
}
}
}



Technorati :

Also Read : IBatis vs Hibernate ? Which one to choose?
IBatis Tutorial – Sample Application Step 1

Related Posts with Thumbnails

Advertisement

Leave a Reply