I'm trying to compare the performance of 2 queries by getting a connection, prepare the statement and execute query.
Capturing the time taken using System.currentTimeMillis()
before and after executeQuery()
.
Ironically whatever may be the query, time taken is always the same.(Ignoring the first execution)
Can someone please let me know, how to get the correct time taken by the query to execute ?
Code snippet:
Connection conn = DriverManager.getConnection(url,"721junits","721junits");
Statement stmt = conn.createStatement();
ResultSet rs;
long startTime = System.currentTimeMillis();
rs = stmt.executeQuery(sql);
long endTime = System.currentTimeMillis();
conn.close();
System.out.println("Total time taken : "+ (endTime - startTime));