Java Reference
In-Depth Information
Listing 2.4
Main.java
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.Resources;
import java.io.Reader;
import java.util.List;
Configures
iBATIS
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++) {
System.out.println(list.get(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.
2.5.3
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 "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<transactionManager type="JDBC" >
Provides
DOCTYPE
and DTD for
validation
B
Search WWH ::




Custom Search