I am trying to make a didactic software, to fill a Java arrayList with the data of a database table. I have managed to fill it so it seems, because the system.out.println
shows me three objects that are the three objects that are in the database. Once I have filled the arrayList I want to show its contents but it returns the name of the columns equal to the number of objects there are. Could you teach me how to do it?
Deputy code:
Before starting to read, we would have to separate the code into classes and all that, but it was just for testing. since the next test will be to do this same but dumping the data in JTextField
. Without more the code.
public class PruebaArrayListSerializable {
protected static ArrayList<Object> badeDatos = new ArrayList<>();
public static void main(String[] args) throws SQLException {
MySQL mysql = new MySQL();
ResultSet rs = null;
//Object[][] obj = null;
mysql.MySQLConnection("root", "1234", "pedidos");
String sql = "SELECT * FROM clientes";
rs = mysql.consultar(sql);
ResultSetMetaData rsmd = null;
rsmd = rs.getMetaData();
int columnas = rsmd.getColumnCount();
while(rs.next()){
HashMap row = new HashMap();
badeDatos.add(row);
for(int i=1; i<=columnas;i++){
row.put(rsmd.getColumnName(i), rsmd.getColumnCount());
}
}
for(Object o : badeDatos) {
System.out.println(o.toString());
}
}
Thanks in advance