If I run this query in MYSQL to get the time taken for the last query:
SELECT sum(Duration)
FROM INFORMATION_SCHEMA.PROFILING
WHERE QUERY_ID = (SELECT MAX(QUERY_ID) FROM INFORMATION_SCHEMA.PROFILING);
I get a valid single result:
Result:
However, when i run the same query from Java I get zero results back:
try {
String sql = "SELECT SUM(Duration) FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = (SELECT MAX(QUERY_ID) FROM INFORMATION_SCHEMA.PROFILING)";
Connection myCon2 = DriverManager.getConnection(URL, USER, PW);
PreparedStatement myStmt = myCon2.prepareStatement(sql);
ResultSet rs = myStmt.executeQuery(sql);
while (rs.next()){
System.out.println(rs.getDouble(1));
}
}
catch ( SQLException e ) {
e.printStackTrace();
}
I have tried changing datatypes using and a stored procedure all to no avail. The code doesn’t throw an exception it just retunrs O or null depending on which datatype I convert it to?
Matthew Williams is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.