Esempio n. 1
0
  private void insertarSolicitud() {
    int cliente = buscaCodClient(cboCliente.getSelectedItem().toString(), "cliente");

    try {
      // Insertar Solicitud
      String sql =
          "INSERT INTO pedido (id, fecha, cliente, fechapedido) VALUES (NULL, '"
              + z.dateFormat(calFecha.getDate())
              + cliente
              + "', NOW())";
      z.snt = z.con.createStatement();
      z.snt.executeUpdate(sql);

      // insertar ítem
      for (int fila = 0; fila < tabla.getRowCount(); fila++) {
        try {
          String sqlitem =
              "INSERT INTO detallepedido (pedido, articulo, cantidad) VALUES ("
                  + modelo.getValueAt(fila, 0)
                  + ", LAST_INSERT_ID(), "
                  + modelo.getValueAt(fila, 2)
                  + ")";
          z.snt = z.con.createStatement();
          z.snt.executeUpdate(sqlitem);
        } catch (SQLException ex) {
          Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    } catch (SQLException ex) {
      Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex);
    }
  }