配置ibatis操作数据库、需要的jar包

1.导入需要的jar包,链接地址:https://github.com/zhangliqingyun/jarlist/tree/master/ibatis

2.配置ibatis操作数据库,sqlMapConfig.properties配置文件

driver=oracle.jdbc.driver.OracleDriver

url=jdbc:oracle:thin:@127.0.0.1:1521:xe                                 

username=jygc

password=jygc

3.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="sqlMapConfig.properties" />



<!-- Statement namespaces are required for Abator -->

<settings useStatementNamespaces="true" />

<transactionManager type="JDBC">

<dataSource type="SIMPLE">

<property name="JDBC.Driver" value="${driver}"></property>

<property name="JDBC.ConnectionURL" value="${url}"></property>

<property name="JDBC.Username" value="${username}"></property>

<property name="JDBC.Password" value="${password}" />

</dataSource>

</transactionManager>



<!-- SQL Map XML files should be listed here -->

<sqlMap resource="com/rdtsw/xml/xxfw_SqlMap.xml" />

</sqlMapConfig>

4.Xxfw_SqlMap.xml文件配置

<?xml version="1.0" encoding="GBK" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >





<sqlMap namespace="xxfw">



<sql id="paginationStart">

        <![CDATA[

           select * from (select row_.*, rownum rownum_ from (

          ]]> 

  </sql>

  <sql id="paginationEnd">

        <![CDATA[

         )row_ where rownum<=#limit# ) where rownum_>#start#

        ]]>

  </sql>

  

</sqlMap>

5.SqlMapconfig.java文件

public class SqlMapconfig {

private static final SqlMapClient sqlMapper;



static {

try {

Reader reader;

String resource = "SqlMapConfig.xml";

System.out.println(resource);

reader = Resources.getResourceAsReader(resource);

sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);

reader.close();

} catch (IOException e) {

e.printStackTrace();



throw new RuntimeException(

"Error initializing MyAppSqlconfig class.Cause:" + e);

}

}



public static SqlMapClient getSqlMapInstance() {

return sqlMapper;

}

public static void startTransaction() throws SQLException{

sqlMapper.startTransaction() ;

}

public static void endTransaction() throws SQLException{

sqlMapper.endTransaction();

}

public static void commitTransaction() throws SQLException{

sqlMapper.commitTransaction();

sqlMapper.endTransaction();



}

public static SqlMapClient getSqlMapClient() {

 return sqlMapper;

}

}

6.通过接口创建实现类

private static XxfwDao xxfwDao = new XxfwDaoImpl(SqlMapconfig.getSqlMapInstance());

7.写接口实现类

public class XxfwDaoImpl implements XxfwDao{

 private SqlMapClient sqlMapClient;

 public XxfwDaoImpl(SqlMapClient sqlMapClient){

  this.sqlMapClient = sqlMapClient;

  }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值