Created
April 3, 2013 02:25
-
-
Save MinCha/5297964 to your computer and use it in GitHub Desktop.
JDBC MySQL Cursor Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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