Metziop

Actualizar tabla

May 22nd, 2021
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. private void actualizartabla(String user) {
  2.  
  3.         try {
  4.             DefaultTableModel model = new DefaultTableModel();
  5.             jtAsignaciones.setModel(model);
  6.             PreparedStatement ps = null;
  7.             ResultSet rs = null;
  8.             String estatus = "asignado";
  9.             Connection conn = MySQLConection.getConnection();
  10.             String sql = "select idPedidoEmpleado, nombreArreglo,tiempoEstimado,comision"
  11.                     + " from pedidosempleado INNER JOIN catalogoarreglos USING (idArreglo)"
  12.                     + " where user= '"
  13.                     + user
  14.                     + "'AND estatus ='"
  15.                     + estatus
  16.                     + "'";
  17.             ps = conn.prepareStatement(sql);
  18.             rs = ps.executeQuery();
  19.             ResultSetMetaData rsMeta = rs.getMetaData();
  20.             int columnas = rsMeta.getColumnCount();
  21.             model.addColumn("ID");
  22.             model.addColumn("Nombre Arreglo");
  23.             model.addColumn("Tiempo estimado");
  24.             model.addColumn("Comision");
  25.             int[] anchos = {20, 200, 50, 50};
  26.             for (int x = 0; x < columnas; x++) {
  27.                 jtAsignaciones.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  28.             }
  29.             while (rs.next()) {
  30.                 Object[] filas = new Object[columnas];
  31.                 for (int i = 0; i < columnas; i++) {
  32.                     filas[i] = rs.getObject(i + 1);
  33.                 }
  34.                 model.addRow(filas);
  35.             }
  36.         } catch (Exception e) {
  37.             JOptionPane.showMessageDialog(null, "Error al actualizar" + e);
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment