How to deal with the ResultSet in Java and convert it to an Array of int?
<p>I'm really perplexed as to why there's only one value being returned by this set of codes. What I'm trying to do here is to query all the *sense_num* (not primary key) that has the primary key as the parameter. The result should contain 2 or more sense_num and so in every sense_num result, I try to store each element in an int[] array and return the  int array respectively. For e.g the result from this query are sense_num 172 &amp; 173. both of them should already be in the array but when i tested the calling function, what it has received is the last value, 173. </p>

<p>I hope you can help me with this. Thanks!  </p>

<p>public int[] getAllSenseID(int primeID) {</p>

<pre><code>    int[] objects = {};
    String qry = "SELECT sense_num FROM cebuano_sense WHERE id_num = '" + primeID + "'";
    try {
        DatabaseConn db = new DatabaseConn("cebuano_wsd");
        db.connect();
        db.query(qry);
        ResultSet result = db.getResult();
        ResultSetMetaData data = db.getData();


        if (result.next() == true) {

            java.sql.ResultSetMetaData rsmd = result.getMetaData();
            int colNo = rsmd.getColumnCount();
            result.beforeFirst();
            int row = 0;
            System.out.println(colNo + "::&gt; Column Number");

            while (result.next()) {
                objects = new int[colNo + 1];

                int i = 0;
</code></pre>

<p>// object[0] has all the values when I tested it and that's why it only accepts the last //one... how do get or receive both values?</p>

<pre><code>                while (i &lt; colNo) {
                    objects[i] = result.getInt(colNo);

                    //print to test
                    System.out.println(objects.length + " &gt;&gt; Count  of Objects");
                    System.out.println(i + " :: " + objects[i] + " &gt;&gt; result");
                    i++;
                }

            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }

    return objects;
}
</code></pre>
