检查SQL查询的延迟

时间:2015-01-23 16:13:49

标签: java mysql latency

所以我编写了一个Java类,使用JDBC连接到MySQL数据库,我有一个查询:

select name from hr order by rand() limit 1;

我要做的是检查延迟,所以我想知道是否有更好的方法来检查延迟或更多的方式比当前:

String query = "select name from hr order by rand() limit 1;";
    try {
        stmt = conn.createStatement();

        long startTime = System.nanoTime();

        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String value = rs.getString("name");
        }

        long endTime = System.nanoTime();
        long duration = (endTime - startTime);
        double seconds = (double)duration / 1000000000.0;
        System.out.println(seconds);
    }

0 个答案:

没有答案