首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ibatis开发环境筹建

2012-06-27 
ibatis开发环境搭建因为项目需要需要使用IBATIS作为数据持久层,于是就着手搭建个简单的IBATIS的开发环境,

ibatis开发环境搭建

因为项目需要需要使用IBATIS作为数据持久层,于是就着手搭建个简单的IBATIS的开发环境,具体详情如下:
1.需要:ibatis-2.3.0.677.jar(ibatis依赖包)和ojdbc14.jar(oracle驱动包)两个包即可。目录如下图:


ibatis开发环境筹建

2.在classpath路径下放: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>
??? <transactionManager type="JDBC">
??? ?? <dataSource type="SIMPLE">
??? ???? <property name="JDBC.Driver" value="oracle.jdbc.OracleDriver"/>
??? ???? <property name="JDBC.ConnectionURL"
??? ??????????? value="jdbc:oracle:thin:@10.153.195.6:1523:ahcrmb"/>
??? ???? <property name="JDBC.Username" value="DBCONTACTKF"/>
??? ???? <property name="JDBC.Password" value="DBCONTACTKF"/>
??? ???? <property name="Pool.MaximumActiveConnections" value="10" />
???????? <property name="Pool.MaximumIdleConnections" value="5" />
???????? <property name="Pool.MaximumCheckoutTime" value="120000" />
???????? <property name="Pool.TimeToWait" value="500" />
???????? <property name="Pool.PingEnabled" value="false" />
???????? <property name="Pool.PingConnectionsOlderThan" value="1" />
???????? <property name="Pool.PingConnectionsNotUsedFor" value="1" />
??? ????
??? ?? </dataSource>
??? ?</transactionManager>
???? <sqlMap resource="ibatismap/Comm.xml"/>
</sqlMapConfig>

?

3.在Comm.xml编辑:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Comm">
??? <!-- test sql -->
??? <select id="test" result+ e);
??? ??? } finally {
??? ??? ??? if (reader != null) {
??? ??? ??? ??? try {
??? ??? ??? ??? ??? reader.close();
??? ??? ??? ??? } catch (IOException e) {
??? ??? ??? ??? ??? e.printStackTrace();
??? ??? ??? ??? }
??? ??? ??? }
??? ??? }
??? }

??? public static SqlMapClient getSqlMapInstance() {
??? ??? return sqlMap;
??? }
???
??? public static void main(String[] args) {
??? ??? Integer in;
??? ??? try {
??? ??? ??? in = (Integer) sqlMap.queryForObject("test");
??? ??? ??? System.out.println(in.toString());
??? ??? } catch (SQLException e) {
??? ??? ??? // TODO Auto-generated catch block
??? ??? ??? e.printStackTrace();
??? ??? }
??? }

}
运行即可完成;

?

热点排行