'Casting a long javax.servlet.jsp.jstl.sql.Result to list of Strings is very slow
The for loop at the end of this is very slow when there are 50k rows. Is there a quicker way to get a list of Strings from the rows of a javax.servlet.jsp.jstl.sql.Result? Use a different collection? Convert the Strings differently?
The query is absolutely fine. I am not including here the custom objects that are used to run it. I can't change them. I think you only need to know that it returns a Result.
(I didn't write any of this code.)
private int m_ObjectGroupId;
private int m_FetchSize;
private ArrayList<String> m_InternalIds;
...method following member initialisation...
String internalIdString = "INTERNALID";
String selectSql = "SELECT " + internalIdString + " FROM MODELOBJECT WHERE OBJECTGROUPID = ?";
ArrayList<Object> valuesToSet = new ArrayList<Object>();
valuesToSet.add(m_ObjectGroupId);
BaseForPreparedStatement selectStatement = new BaseForPreparedStatement(selectSql.toString(), valuesToSet);
SqlQueryResult queryResult = DBUtils.executeQueryRS(p_Context, selectStatement, getConnection(), m_FetchSize);
Result result = queryResult.getResult();
m_InternalIds = new ArrayList<>(result.getRowCount());
for (int i = 0; i < result.getRowCount(); i++) {
m_InternalIds.add((String)result.getRows()[i].get(internalIdString));
}
UPDATE: The query only takes 1s whereas the loop takes 30s. result.getRows().getClass() is a java.util.SortedMap[].
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
