I have defined a variable with
Object[] data;
How can I fill it up with data in the next step?
I want to do something like this:
public Object[] select() {
Object[] data; // Here I definded it
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM CUSTOMERS");
while (rs.next()) {
/* data = {(rs.getString("fname"), (rs.getString("lname")); */
// I know it's wrong, but how can I fill it with data from a database?
}
rs.close();
stmt.close();
} catch (SQLException ex) {
System.out.println("error while selecting");
System.err.println(ex);
}
return data;
}
// -----
// somewhere else
model.addRow(DB.INSTANCE.select());