Note that there are some explanatory texts on larger screens.

plurals
  1. POFail adding objects to an ArrayList. Always copies the same
    text
    copied!<p>To add different objects from the database to an <code>ArrayList</code> this is the code that I use:</p> <pre><code>try { Statement stat = con.createStatement(); ResultSet rs = stat.executeQuery("SELECT DISTINCT Id, Username, FirstName, LastName FROM USER WHERE Username LIKE '%"+name+"%' or FirstName LIKE '%"+name+"%' or LastName LIKE '%"+name+"%'"); while (rs.next()){ finded.setUsername(rs.getString("Username")); finded.setFirstName(rs.getString("FirstName")); finded.setLastName(rs.getString("LastName")); finded.setId(rs.getInt("Id")); findList.add(finded); Log.d("this is the content of the List:",((Integer) findList.get(j).getId()).toString()); Log.d("this is the content of the List 0:",((Integer) findList.get(0).getId()).toString()); } con.close(); </code></pre> <p>And this is what the Log.d gives me each time. </p> <pre><code>10-18 08:31:39.407: D/this is the content of the List:(427): 3 10-18 08:31:39.407: D/this is the content of the List 0:(427): 3 10-18 08:31:39.427: D/this is the content of the List:(427): 15 10-18 08:31:39.427: D/this is the content of the List 0:(427): 15 10-18 08:31:39.437: D/this is the content of the List:(427): 13 10-18 08:31:39.437: D/this is the content of the List 0:(427): 13 10-18 08:31:39.447: D/this is the content of the List:(427): 50 10-18 08:31:39.447: D/this is the content of the List 0:(427): 50 10-18 08:31:39.460: D/this is the content of the List:(427): 34 10-18 08:31:39.460: D/this is the content of the List 0:(427): 34 10-18 08:31:39.467: D/this is the content of the List:(427): 49 10-18 08:31:39.467: D/this is the content of the List 0:(427): 49 10-18 08:31:39.479: D/this is the content of the List:(427): 53 10-18 08:31:39.479: D/this is the content of the List 0:(427): 53 </code></pre> <p>As you can see it copies the same object in all the position of the <code>ArrayList</code>. I tried also to do it with <code>findList.add(index, finded)</code> (<code>index</code> is an <code>int</code> who is incrementing) But I get the same result.</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