Java Database Development (3) - Supplement

1. SQL injection and prevention

Use PreparedStatement instead of Statement object, which provides a way to parameterize SQL

2. Affairs

definition

Transaction is the basic unit of concurrency control and satisfies ACID characteristics

  • Atomicity: atomicity
  • Consistency: consistency
  • Isolation: isolation
  • Persistence: durability

    transaction control

    Connection
    • .setAutoCommit() : start a transaction
    • .commit() : commit the transaction
    • .rollback() : rollback the transaction
    • .setSavepoint() : set a breakpoint

    3. Cursor

    The cursor provides a mechanism for the client to read part of the server-side result set. Use useCursorFetch=true to open the setFetchSize() method of the PreparedStatement interface to set the number of reads.

    Four, stream read

    Read large objects (large fields) in binary stream mode

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

    5. Batch processing

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325068552&siteId=291194637