I am creating a basic SQL editor using java and I'm wondering how I could create a 2d array which stores each 'Persons' data in one arraylist. I have a database named contactdetails which stores each persons Contact ID, full name, email, phone number etc. and it was just to see if anyone could drop some code in the comments as to how I could go about this? Here is the current code I am using to retrieve from the database:
public void SELECTALL() {
db.Connnect();
Connection conn = db.getConnection();
if (conn!=null) {
try {
String SQL = "SELECT * FROM (?);";
PreparedStatement stmt = conn.prepareStatement(SQL);
//Gathering which table the user wants to view
Scanner s = new Scanner(System.in);
System.out.println("Enter name of table");
String TABLENAME = s.nextLine();
//Inserting table name into SQL command
stmt.setString(0, TABLENAME);
//Executing query
ResultSet rs = stmt.executeQuery();
//Displating data to user
while (rs.next()) {
//DATA GETS STORED IN 2D ARRAY SO EACH PERSON GETS OWN PERSONAL INTEGER TO BE CALLED BY E.G soandso.get(4)
}
} catch (SQLException err) {
System.err.println(err);
}
}
}
Thanks people. any feedback would be great as well.