JDBC connection hangs at executing rs.next()
-
09-06-2021 - |
Pregunta
I'm trying to read from a mySQL server (in my LAN) a huge resultSet. I implemented it the way I found looking for the setFetchSize
method: BalusC's Example. So I did:
con = DriverManager.getConnection(url, user, password);
//con.setAutoCommit(false);
st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
st.setFetchSize(Integer.MIN_VALUE);
rs = st.executeQuery(query);
int count = 0;
while (rs.next ()) {
// Process entry
String rsc = rs.getString ("resource");
String tpc = rs.getString("topic");
System.out.println(count + ": " + rsc);
++count;
}
Although, it hangs at row 1077 at the line rs.next()
. It doesn't throw exception.
EDIT:
After a timeout something new happened. It returned this error message:
JDWP exit error JVMTI_ERROR_NONE(0): getting frame location [../../../src/share/back/stepControl.c:641]
This error seems to be unrelated.
EDIT2: I've coded a PHP script for retrieving results by stream and happens exactly the same. So it has nothing to do with JDBC... I don't know what is going on!!
Solución 2
OKay, the problem was at the query itself.
I've found that streaming is very sensitive on how query is built. If I make a little change (like adding SELECT DISTINCT) it buffers or hangs. Finally, I left a column out of the query and worked...
Otros consejos
The second error message is a deadlock in the Eclipse debugger when hot-swapping and/or JRebel (source):
It is a known problem, actually two problems.
1) Eclipse debugger deadlocks sometimes on hot-swapping (true for any version of JRebel).
2) JVM crash on hotswapping - it is true for JRebel 4M1.We are expecting bugfix release soon (3.6.2 together with Eclipse plugin) - It will fix first problem. Second problem should be fixed with 4M2 release.
Suggestions:
- Update Eclipse to 3.7.2 and JRebel to the latest release
- Start the application again.
- Use logging/
System.out.println()
to debug - Check the log of your mysql server for problems (harddisk, network)
- Run the query in a SQL workbench (to see whether this is a problem in the query/the server or your code)