title: JDBC INSERT ... SELECT Prepared Statement quietly failing to update database
body: <p>Very much a beginner, this relates to a college project and as such I understand if you are unwilling to solve the problem for me, but I would appreciate being pointed in the right direction if possible.</p>
  <p>The below code is a snippet from my database management class for a project.</p>
  <p>I'm keeping an ArrayList of users within the java project, loading it if possible from the database at runtime and saving back to the database when closed. Any changes to the users are made in the app (just a JavaFX GUI) and only reflected in the database at shutdown.</p>
  <p>For this reason, I need it to be a &quot;INSERT IF NOT EXISTS&quot; type of statement.
  I tried this originally without the complex INSERT...SELECT, it just plain inserted the user, causing duplicates. This caused duplicates, but otherwise worked, updating and reading from the database as expected with no errors, even on the ArrayList to byte array to BLOB part, which was very much stretching my Java ability.</p>
  <p>I also understand that there are some examples of poor encapsulation in my code, but I am more concerned with the fact that the code runs, no errors, and even in the debugger the prepared statement seems to be getting formed correctly, but the database fails to be updated, with or without duplicates.
  Any help, whether a solution, work around or suggestion as to where to go looking for a cause, would be much appreciated.</p>
  <pre><code>    public static void saveUsers(ArrayList&lt;User&gt; users){
      
      makeConn();
      try{
      for (User u : carbonapp.CarbonApp.userList.users){
          String n = u.getName();
          String p = u.getPass();
          boolean a = u.getIsAdmin();
          UserActivityList l = u.list;
          byte[] m = null;
          try {
              m = toByteArray(l.getUserActivities());
          } catch (IOException ex) {
              Logger.getLogger(dbStor.class.getName()).log(Level.SEVERE, null, ex);
          }
          Blob ualblob = new SerialBlob(m);
          String sql = &quot;INSERT INTO root.person (name,pass,isAdmin,ual)\n&quot; +
              &quot;SELECT CAST(? as VARCHAR(50)),CAST(? as VARCHAR(50)),CAST(? as BOOLEAN),CAST(? as BLOB) &quot; +
              &quot;FROM root.person WHERE NOT EXISTS (SELECT name FROM root.person WHERE name = ? AND pass = ?)&quot;;
              pstmt = conn.prepareStatement(sql);
              pstmt.setString(1, n);
              pstmt.setString(2, p);                
              pstmt.setBoolean(3, a);
              pstmt.setBlob(4, ualblob);
              pstmt.setString(5, n);
              pstmt.setString(6, p);
              pstmt.executeUpdate();
              conn.commit();
          }}catch(SQLException se){se.printStackTrace();
      }try{conn.close();
      }catch(SQLException se){se.printStackTrace();}
  }
  </code></pre>
  <p>FYI, I'm using a derby database, working in Netbeans. The <code>makeConn();</code> function creates the connection and works in other cases, it sets a <code>static Connection conn</code> which is used in the shown code.
  Again, no error messages, no crashes or other issues there, just an empty table &quot;person&quot;, the desired result being that the table gets updated with the values, in the case that those values don't exists already.</p>