Java Reference
In-Depth Information
Listing 2.4
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.Resources;
import java.util.List;
public class Main {
public static void main(String arg[]) throws Exception {
String resource = "SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader (resource);
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
List list = sqlMap.queryForList("getAllUsers", "EMPLOYEE");
System.out.println("Selected " + list.size() + " records.");
for(int i = 0; i < list.size(); i++) {
Prints the results
Executes the statement
That's it! We've configured i BATIS , executed the statement, and printed the
results in about 10 lines of Java code. That's all the Java code required for a fully
functional i BATIS application. Later, we will refine how things happen, but for
now, let's move on to the basics of the configuration.
Configuring iBATIS (a preview)
Since we cover the configuration of i BATIS in depth in the next chapter, we dis-
cuss it only briefly here. You won't find much in the way of explanation of the
options here, but we cover the essential information.
First, let's look at the SqlMapConfig.xml file. This is the starting point for i BA-
TIS , and ties all of the SQL Maps together. Listing 2.5 contains the SqlMapCon-
fig.xml file for our simple application.
Listing 2.5
The SQL map configuration for the simplest iBATIS application ever written
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-// SQL Map Config 2.0//EN"
<transactionManager type="JDBC" >
and DTD for
Search WWH ::

Custom Search