I have the following and I get the error
java.lang.String cannot be cast to [Ljava.lang.String;
I have changed the Object[]
to String[]
because I faced the next error:
java.lang.Object cannot be cast to [Ljava.lang.String;
Any idea?
private Collection queryStatement(String SelectStatement) {
int colcount = 0;
int rowcount = 0;
int rowcounter = 0;
ArrayList a = new ArrayList();
Query query = getEntityManager().createNativeQuery(SelectStatement);
List<String[]> resultList = (List<String[]>) query.getResultList();
if (!resultList.equals(Collections.emptyList())) {
rowcount = resultList.size();
}
if (rowcount > 0) {
colcount = ((String[]) query.getResultList().get(0)).length;
}
rows = rowcount;
cols = colcount;
String[][] array = new String[rowcount][colcount];
for (String[] obj : resultList) {
String[] record = new String[colcount];
for (int colCounter = 0; colCounter < colcount; colCounter++) {
record[colCounter] = safeValue(obj[colCounter]+"");
}
array[ rowcounter++] = (String[]) record;
}
a.add(array);
return a;
}
List<String[]>
? It looks like it's returning aList<String>
, hence the error. – ZeitgeistList<String[]>
instead of treating that as one of the possibilities. – OrangemanSELECT *
, but you're only selecting 1 attribute. – Zeitgeist