我想知道执行 SQL 查询需要多长时间。 jdbc 层似乎没有报告这个,我在 MyBatis 日志中也找不到它。我不敢相信没有办法轻松获得这个?
最佳答案
您可以使用 (org.apache.commons.lang.time) 包中的秒表。所以它会在你的 java 代码中运行,在你添加依赖项/将 StopWatch 导入你的 java 类之后你会得到这样的东西
StopWatch sw = new StopWatch();
sw.start();
// query you want to measure the time for
sw.stop();
long timeInMilliseconds = sw.getTime();
System.out.println("Time in ms is: " + timeInMilliseconds );
// or maybe log it if you like?
关于java - 通过 MyBatis 记录 SQL 查询时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26802943/