Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Mentioned your error is that you never re-read <code>rowData</code> from your database and that every index in your array is set to the same value which is only read from one column, by this code here:</p> <pre><code>resTablesData1.next(); String rowData = resTablesData1.getString(db1ColName); for (int j=0; j&lt;db1RowNum; j++) { System.out.println(); for (int k=0; k&lt;db1ColNum; k++) { columnsArrayDB1[j][k] = rowData; System.out.println("|-----------------------------------------------------|"); System.out.print("| "+columnsArrayDB1[j][k]+" |"+"\t"); System.out.println("|-----------------------------------------------------|"); } } </code></pre> <p>You need to loop for each row in <code>resTablesData1</code> and then get the data from each column (Assuming <code>resTablesData1</code> is a <code>ResultSet</code>)</p> <pre><code>int j = 0; while(resTablesData1.next()) { ResultSetMetaData rsmd = resTablesData1.getMetaData(); int colCount = rsmd.getColumnCount(); System.out.println(); for (int k=0; k&lt;colCount ; k++) { String colName = rsmd.getColumnName(i); Object o = resTablesData1.getObject(colName); columnsArrayDB1[j][k] = o.toString(); System.out.println("|-----------------------------------------------------|"); System.out.print("| "+columnsArrayDB1[j][k]+" |"+"\t"); System.out.println("|-----------------------------------------------------|"); } j++; } </code></pre> <p>But, you are far better off creating an Object which would represent the data of the row. Then for each row received you could create a new instance of this Object and then add this to a List of these objects. Then you also only need to query the database once.</p> <p>Something like this for example:</p> <pre><code>public class RowDataObject { public String col1; public String col2; // Etc public RowDataObject(String aCol1, String aCol2 /*.....etc */ ) { col1 = aCol1; col2 = aCol2; //...etc } } </code></pre> <p>Then to read data</p> <pre><code>List&lt;RowDataObject&gt; allRows = new ArrayList&lt;RowDataObject&gt;(); ResultSet rs = //Your Query while (rs.next()) { String c1 = rs.getString("A Column Name or Index"); String c2 = rs.getString("A Column second Name or Index"); //...etc allRows.add(new RowDataObject(c1,c2......)); } </code></pre> <p>Then do your print operations from the List</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload