美文网首页
Java数据库开发(三)之——补充

Java数据库开发(三)之——补充

作者: ledge | 来源:发表于2018-04-28 08:02 被阅读0次

一、SQL注入与防范

使用PreparedStatement替代Statement对象,它提供了参数化SQL的方式

二、事务

定义

事务是并发控制的基本单位,满足ACID特征

  • 原子性:atomicity
  • 一致性:consistency
  • 隔离性:isolation
  • 持久性:durability

事务控制

Connection
  • .setAutoCommit():开启事务
  • .commit():提交事务
  • .rollback():回滚事务
  • .setSavepoint():设置断点

三、游标

游标提供一种客户端读取部分服务器端结果集的机制,通过useCursorFetch=true开启

通过PreparedStatement接口的setFetchSize()方法设置读取数

四、流方式读取

采用二进制流方式读取大对象(大字段)

while (rs.next()) {
    //获取对象流
    InputStream in = rs.getBinaryStream("blog");
    //将对象流写入文件
    File f = new File(FILE_URL);
    OutputStream out = null;
    out = new FileOutputStream(f);
    int temp = 0;
    while ((temp = in.read()) != -1){
        //边读边写
        out.write(temp);
    }
    in.close();
    out.close();
}

五、批处理

六、MyBatis

http://www.mybatis.org/mybatis-3/zh/index.html

相关文章

网友评论

      本文标题:Java数据库开发(三)之——补充

      本文链接:https://www.haomeiwen.com/subject/gkkwlftx.html