Created
February 9, 2017 05:57
-
-
Save sulmansarwar/02ee4aa30da951efea57bf339f6cd78d to your computer and use it in GitHub Desktop.
1- Retrieve data using JDBC
2- Populate java.util.List from java.sql.ResultSet
3- Paginate java.util.List
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
String query = "SELECT DISTINCT article_id from articles WHERE article_summary IS NULL"; | |
SqlConnection connection = new SqlConnection(); | |
SqlCommand command = new SqlCommand(query, connection.getDatabaseConnection()); | |
ResultSet resultSet = command.executeSelect(); | |
int counter = 1; | |
List idList = new ArrayList(); | |
//populate List::idList | |
while (resultSet.next()) { | |
idList.add(resultSet.getInt("article_id")); | |
} | |
int start = 0; | |
int end = 0; | |
int pageSize = 10; | |
do { | |
start = end; | |
if ((idList.size() - start) < pageSize) { | |
pageSize = (idList.size() - start); | |
} | |
end = start + pageSize; | |
List subList = idList.subList(start, end); | |
System.out.println(counter++ + " - " + subList); | |
} while (((idList.size() - start) > pageSize)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment