I have a 2D String array populated with the following method in my Main class:
public static String[][] dbTable() throws SQLException { String[][] dbTable = null; table = conn.createStatement(); String sql = "select * from Java_Test_Profiles"; ResultSet rs = table.executeQuery(sql); rs.last(); int rowNumb = rs.getRow(); ResultSetMetaData rsmd = rs.getMetaData(); int columnS = rsmd.getColumnCount(); rs.beforeFirst(); dbTable= new String[rowNumb][columnS]; int i=0; while(rs.next() && i<rowNumb && rowNumb<100) { for(int j=0;j<columnS;j++) { dbTable[i][j] = rs.getString(j+1); } i++; } return dbTable; "dbTable" is passed between several classes, and I was wondering how I can create a copy of this for editing. I want to do this because i need to "re-load" the contents of the array back to their original state. I have tried to call main.dbTable() but that returns exactly what has already been edited, not what is contained within the database.
main.dbTable()would return the edited array. Your method is also leaking resources like a wounded soldier is leaking blood.ConToDatabase.dbTable()returns the same. I tested this by doingArrays.deepToString(dbTable)Connection,StatementandResultSetin your method. But how do you explain that by editing an array you're modifying the contents of the database? Because that's what seems to be happening by your telling, yet the code shows that it should be impossible (unless you're saving the modified array back to the database elsewhere).