title: Prepared statement updating only some fields from Jtextfields
body: <p>im doing an inventory software, and i have a modify frame where you introduce an id and then you can select the fields that you are going to update, the fields are JtextField and you select them by checkBoxes.
  The software have spanish words, so if you don't understand what it means feel free to ask. </p>
  
  <p><a href="https://i.stack.imgur.com/6jzRi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6jzRi.png" alt="This is the frame"></a> </p>
  
  <p>I have the preparedStatement code, but it updates all the fields. I don't know if there is a code to only do an update from checked fields.</p>
  
  <pre><code> public static void modificar(int id,String nombre,String marca,String descripcion,String tamaño,String departamento,float precio) throws SQLException
          {
              Connection conn = null;
      PreparedStatement prepStmt = null;
      ResultSet rs = null;
      try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          String connectionUrl = "jdbc:mysql://localhost:3306/inventario";
          String connectionUser = "root";
          String connectionPassword = "root";
          conn = (Connection) DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
          String sqlStmt = "UPDATE Producto SET nombre=?, marca=?,descripcion=?,tamaño=?,departamento=?,precio=? WHERE idProducto='"+id+"'";
          prepStmt = conn.prepareStatement(sqlStmt);
  
                    if(!nombre.isEmpty()){
          prepStmt.setString(1, nombre);
                    }
                    if(!marca.isEmpty()){
          prepStmt.setString(2, marca);
                    }
                    if(!descripcion.isEmpty()){
                      prepStmt.setString(3, descripcion);
                    }
                    if(!nombre.isEmpty()){
                    prepStmt.setString(4, tamaño);
                    }
                    if(!departamento.isEmpty()){
          prepStmt.setString(5, departamento);
                    }
                    if(precio!=0){
                      prepStmt.setFloat(6, precio);
                    }
          prepStmt.executeUpdate();
  
      } catch (Exception e) {
          e.printStackTrace();
      } 
  </code></pre>
  
  <p>all i can think about is to write methods for every possible combination. I hope you can help me, Thanks.</p>