Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use multidimensional arrays with array list?
    primarykey
    data
    text
    <p>I want to add some records from sql query but the output is not correct. Always return the last record. </p> <p>The correct list is : </p> <p>John</p> <p>Nick</p> <p>Mary</p> <p>Joe</p> <p>,but always return Joe.</p> <p>This is the method to add the elements:</p> <pre><code>public ArrayList&lt;String[][]&gt; getFiledArrayList() { // ArrayList&lt;String[][]&gt; fieldsList = new ArrayList&lt;&gt;(); String[][] tempRow = new String[1][2]; ResultSet result; String sql = "select id, name_of from field"; result = database.exeQueryStatement(sql); try { while(result.next()) { tempRow[0][0] = result.getString("id"); // System.out.println(tempRow[0][0]); tempRow[0][1] = result.getString("name_of"); // System.out.println(tempRow[0][1]); fieldsList.add(tempRow); System.out.println(fieldsList.get(0)[0][1]); } } catch (SQLException ex) { Logger.getLogger(FieldManage.class.getName()).log(Level.SEVERE, null, ex); } return fieldsList; </code></pre> <p>I put the <code>id</code> and the <code>name_of</code> in a <code>String[1][2]</code> table and I want to show the <code>name_of</code> in a jComboBox. Ι want to make an insert and watch the <code>name_of</code> with <code>id</code></p> <pre><code>FieldManage fieldmanage = new FieldManage(); ArrayList&lt;String[][]&gt; listOfField; listOfField = fieldmanage.getFiledArrayList(); String[] fields = new String[listOfField.size()]; System.out.println(listOfField.get(0)[0][0]); for (int i=0; i&lt;listOfField.size(); i++) { fields[i] = listOfField.get(i)[0][1]; System.out.println(fields[i]);//test print show always joe! } jComboFields.setModel(new javax.swing.DefaultComboBoxModel(fields)); </code></pre> <p>This code always return Joe.</p> <p>Also I want to know if there is better way to match an jcombo element with an <code>id</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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