I get a out of memory heap space error at- oRsSelect = oPrStmt.executeQuery(); This is the function that retrieves a million records from a mysql table called 'snomedinfo_data':
public String getSnomedCodes()
{
Root oRoot = null;
JSONObject oJsonSno = null;
JSONObject oJson = null;
JSONArray oJsonArr = null;
ResultSet oRsSelect = null;
PreparedStatement oPrStmt = null;
String strSql = null;
String snomedcode=null;
String snomeddesc=null;
String str=null;
int cStart = 0;
try {
oJsonSno = new JSONObject();
oJson = new JSONObject();
oJsonArr = new JSONArray();
oRoot = Root.createDbConnection(null);
//retrieving data from table
strSql = "SELECT * FROM snomedinfo_data ;";
oPrStmt = oRoot.con.prepareStatement(strSql);
oRsSelect = oPrStmt.executeQuery();
while (oRsSelect.next()) {
snomedcode = Root.TrimString(oRsSelect.getString("conceptid"));
snomeddesc = Root.TrimString(oRsSelect.getString("term"));
oJsonSno = new JSONObject();
oJsonSno.put("snomedcode",snomedcode);
oJsonSno.put("snomeddesc",snomeddesc);
oJsonArr.put(oJsonSno);
}
oJson.put("status", "success");
oJson.put("snomeddata", oJsonArr);
str = oJson.toString();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
oRsSelect = Root.EcwCloseResultSet(oRsSelect);
oPrStmt = Root.EcwClosePreparedStatement(oPrStmt);
oRoot = Root.closeDbConnection(null, oRoot);
}
return str;
}
I get a out of memory heap space error at- oRsSelect = oPrStmt.executeQuery();
I have tried using -
strSql = "SELECT * FROM snomedinfo_data ;";
oRoot.con.setAutoCommit(false);
oPrStmt = oRoot.con.prepareStatement(strSql);
oPrStmt = oRoot.con.prepareStatement(strSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
oPrStmt.setFetchSize(Integer.MIN_VALUE);
oRsSelect = oPrStmt.executeQuery();
But it still does not work and continues to give the out of memory heapspace error.please help!!