JDBC iBatis Hibernate的区别及各自的优缺点总结

1.   JDBC: 面向数据的,SQL直接写在代码中,不方便使用维护,但效率高安全性好

       try(PreparedStatement psts = connection.prepareStatement("SELECT F01 FROM S71.T7101 WHERE F02 =       ?)")){
                 psts.setInt(1, 111);
                 try(ResultSet resultSet = psts.executeQuery()){
                     if(resultSet.next()){
                        
                     }
            }
           
                
            }


2.   iBatis:  面向对象的,对JDBC的轻量级封装。优点:灵活写SQL,自动映射PO对象,适合于大数据、多表联查和复杂的数据库操作

Java代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8" ?>   
  2.   
  3. <!DOCTYPE sqlMap         
  4.     PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"         
  5.     "http://ibatis.apache.org/dtd/sql-map-2.dtd">   
  6.   
  7. <sqlMap>   
  8.   
  9.   <!-- Use type aliases to avoid typing the full classname every time. -->   
  10.   <typeAlias alias="User" type="com.app.model.User"/>   
  11.   
  12.   <!-- Select with no parameters using the result map for Account class. -->   
  13.   <select id="selectAllUsers" resultClass="User">   
  14.     select * from t_user   
  15.   </select>   
  16.      
  17.   <select id="selectUser" resultClass="User" parameterClass="int">   
  18.     select * from t_user where id=#id#   
  19.   </select>   
  20.      
  21.   <insert id="insertUser" parameterClass="User">   
  22.     insert into t_user values (   
  23.         null,#username#,#password#   
  24.     )   
  25.   </insert>   
  26.      
  27.   <update id="updateUser" parameterClass="User">   
  28.     update t_user set username = #username#,password=#password#   
  29.     where id=#id#   
  30.   </update>   
  31.      
  32.   <delete id="deleteUser" parameterClass="int">   
  33.     delete from t_user where id=#id#   
  34.   </delete>   
  35. </sqlMap>  

3.   Hibernate:   面向对象的,JDBC的重量级封装。优点:有缓存,使用方便快捷,不用写SQL    缺点:封装太多,性能不好,SQL不能优化

  • <?xml version="1.0"?>  
  • <!DOCTYPE hibernate-mapping PUBLIC  
  •           "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
  •           "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
  • <hibernate-mapping>    
  • <class name="Customer" table="customer">  
  • <id name="id" column="CID">  
  • <generator class="increment" />   
  • </id>        
  • <property name="username"   
  • column="username" />  
  • <property name="password"   
  • column="password" />   
  • </class>
  •  </hibernate-mapping>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值