I want to put all the data that I have in my database in an ArrayList.
ResultSet rs = callableStatement.executeQuery();
ArrayList<Object> list = new ArrayList<Object>();
List<ArrayList> table = null;
while (rs.next()) {
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) {
System.out.print(" " + rs.getMetaData().getColumnName(i) + "=" + rs.getObject(i));
String data = rs.getString(i);
list.add(data);
}
table.add(list);
System.err.println(table);
}
I am printing all the data in my database correctly. My problem is that I'm getting
java.lang.NullPointerException
list.get(9)You need to loop through each index in the list. Also, you should be usingSystem.out.println()instead ofSystem.err.println(). Although, your IDE will print them both to the console,errshould be designated for errors.list.get(9)I'm printing the 9th column (but just the first element, I want all the elements). Doing thesys.errjust so it's in redlist.get(9)will print the9th element of theListrs.next()