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

一、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();
    }

    五、批处理

猜你喜欢

转载自www.cnblogs.com/gxyan/p/8965850.html