mardi 6 janvier 2015

Convert Stored Procedure result to SQLite table

While writing a Java application which uses data from server, I wanted to have a fallback plan. e.g. if the connection to the remote database could not be establish then use the locally cached data from previous version.


my initial approach is to create an SQLite database locally and populate it with the data from Stored Procedure call whenever the remote database connection is available and then use this SQLite database for rest of the work in application.


The things I couldn't figure out are how to convert the ResultSet to SQLite table.


A simple form of my stored procedure call is,



try (PreparedStatement cs = dbConnection.prepareCall("{call myStoredProcedure (?)}")) {
cs.setInt(1, id);
ResultSet rs = cs.executeQuery();
if (rs != null) {
while (rs.next()) {
// perform some operation here
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}


It would be a great help if someone can point me in a right direction to convert this ResultSet to SQLite table.


Aucun commentaire:

Enregistrer un commentaire