title: How do you determine if an insert or update was successful using Java and MySQL?
body: <p>I am using Java to connect to a MySQL database.  I am trying to insert or update data into the database. </p>
  
  <p>Even though I am quite sure the insert was successful, it returns false. </p>
  
  <p>According to the "execute" API, the return value is "true if the first result is a ResultSet object; false if it is an update count or there are no results".  </p>
  
  <p>How can I determine whether or not my insert or update was successful?</p>
  
  <pre><code>    public boolean insertSelections(String selection, String name){
          String sql ="INSERT INTO WORKREPORT VALUES (?,?,?,?,?)";
          boolean action = false;
          try {
              PreparedStatement stmt = conn.prepareStatement(sql);
              SimpleDateFormat dateFormat =  new java.text.SimpleDateFormat("yyyy：MM：dd hh:mm:ss");
              String formatDate = dateFormat.format(new java.util.Date(System.currentTimeMillis())); 
              java.util.Date mDate = dateFormat.parse(formatDate);
              java.sql.Timestamp timeStamp = new java.sql.Timestamp(System.currentTimeMillis());
  //          Date time= new Date(mDate.getTime());
  
              stmt.setInt(1, Integer.parseInt(getNumberByName(name).trim()));
              stmt.setString(2, name);
  //          stmt.setDate(3, time);
              stmt.setTimestamp(3, timeStamp);
              stmt.setString(4, selection);
              stmt.setString(5, "N/A");
              action = stmt.execute();
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }   catch (ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }   
          return action;
      }
  </code></pre>