properties:
JDBC.Driver=com.mysql.jdbc.Driver
JDBC.ConnectionURL=jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=utf-8
JDBC.Username=root
JDBC.Password=123456
SqlMapConfig.xml
<?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>
<properties resource="com/tr/mysql/jdbc.properties"/>
<!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource -->
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${JDBC.Driver}"/>
<property name="JDBC.ConnectionURL" value="${JDBC.ConnectionURL}"/>
<property name="JDBC.Username" value="${JDBC.Username}"/>
<property name="JDBC.Password" value="${JDBC.Password}"/>
</dataSource>
</transactionManager>
<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/tr/mysql/person.xml"/>
<!-- List more here...
<sqlMap resource="com/mydomain/data/Order.xml"/>
<sqlMap resource="com/mydomain/data/Documents.xml"/>
-->
</sqlMapConfig>
运行类,初始化对象:
private static SqlMapClient sqlMapClient = null;
static{
try {
Reader reader = Resources.getResourceAsReader("com/tr/mysql/SqlMapConfig.xml");
sqlMapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}