Skip to content

Instantly share code, notes, and snippets.

@MinCha
Created April 3, 2013 02:25
Show Gist options
  • Save MinCha/5297964 to your computer and use it in GitHub Desktop.
Save MinCha/5297964 to your computer and use it in GitHub Desktop.
JDBC MySQL Cursor Example
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = template.getDataSource().getConnection();
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
rs = stmt.executeQuery("SELECT * FROM push");
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2));
Thread.sleep(1000);
}
} finally {
try {
conn.close();
} catch (Exception e) {
}
try {
stmt.close();
} catch (Exception e) {
}
try {
rs.close();
} catch (Exception e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment