在PreparedStatement :: cancel调用之后执行哪一行代码?

时间:2018-07-12 04:22:31

标签: prepared-statement

采用以下代码:

public class A {

    public PreparedStatement pstmt_pointer;
    public void cancel() throws SQLException {
        if(pstmt_pointer != null) {
            System.out.println("Cancelling pstmt_pointer");
            pstmt_pointer.cancel();
        }
    }

    Connection conn;
    public int getCount() throws SQLException {

        long start2 = System.currentTimeMillis();
        String sql = "select count(*) from table";

        int count = 0;
        try (PreparedStatement p_stmt = conn.prepareStatement(sql)) {
            pstmt_pointer = p_stmt;

            ResultSet result = p_stmt.executeQuery();
            result.next();
            count = result.getInt("count");

        }
        long end2 = System.currentTimeMillis();

        long elapsed = end2 - start2;
        double countExecTime = truncate((float) elapsed / 1000);
        System.out.println("Count(*) Execution Time: " + countExecTime + " seconds");

        return count;
    }
    public float totalExecTime;

    private static double truncate(float x) {
        int y = (int) (x * 100);
        return (double) y / 100;
    }
}

如果在仍然执行查询(cancel())时(从另一个线程)调用ResultSet result = p_stmt.executeQuery();接下来执行哪一行代码result.next();被打吗?还是被跳过?代码一旦取消,是否会退出try块?如果p_stmt被取消,此方法的返回值是什么?

我不确定答案是否取决于平台,但我的数据库是Oracle。

0 个答案:

没有答案