I have a very simple table.
╔════╦═══════╗
║ id ║ title ║
╠════╬═══════╣
║ 1 ║ cow ║
║ 2 ║ duck ║
╚════╩═══════╝
ID is INT
TITLE is TEXT
I´m trying to fill an array with these two registers.
collection class has a constructor of (int,String)
My code:
collection[] co=null;
String query="SELECT * FROM collection";
ps=conn.prepareStatement(query);
rs=ps.executeQuery();
int counter=0;
while(rs.next()) {
co[counter]=new colleccion(rs.getInt("id"),rs.getString("title"));
System.out.println(rs.getInt("id"));
System.out.println(rs.getString("title"));
counter++;
}
System.out.println works ok, the values are showed correctly. But it throws an exception as soon as it reaches the array line.
Also tried with column numbers (1 and 2), but it is the same.
Help please.