I am trying to get certain row records from a db_table into an array list. though this has been done many times, mine is a bit more different. suppose I have a table in my database like this below:
+---------+--------+--------+
| NAME | BILL | CONTACT|
+---------+--------+--------+
| james | 400 | 024669 |
| Mavis | 700 | 025550 |
| john | 650 | 029510 |
| bendo | 340 | 023579 |
+---------+--------+--------+
and I want an array to display records like this:
[james,400,024669]
[Mavis,700, 025550]
[John,650, 029510]
[bendoo,340,023579]
please how do I achieve that. the code I wrote gave me only a last array. and its:
ArrayList<String> inner = null;
try{
String sql="select Name,Score,Contact from members";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while (rs.next()) {
inner = new ArrayList<>();
for(int i=1; i<=columnsNumber; i++){
inner.add(rs.getString(i));
}
}
System.out.println(inner);
}catch(Exception e){
}
but this is the only System.out.PrintIn displayed:
[bendoo,340,023579]
BUILD SUCCESSFUL (total time: 2 minutes 13 seconds)
please how do I get this below as my result:
[james,400,024669]
[Mavis,700, 025550]
[John,650, 029510]
[bendoo,340,023579]