Advertisement
Metziop

Untitled

May 22nd, 2021
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. private void actualizartabla() {
  2.  
  3.         try {
  4.             DefaultTableModel model = new DefaultTableModel();
  5.  
  6.             jtAsignaciones.setModel(model);
  7.             jtAsignaciones.setAutoCreateRowSorter(true);
  8.             PreparedStatement ps = null;
  9.             ResultSet rs = null;
  10.             Connection conn = MySQLConection.getConnection();
  11.             String sql = "SELECT idPedidoEmpleado,estatus,user FROM pedidosempleado WHERE sucursal1='Matriz'";
  12.             ps = conn.prepareStatement(sql);
  13.             rs = ps.executeQuery();
  14.             ResultSetMetaData rsMeta = rs.getMetaData();
  15.             int columnas = rsMeta.getColumnCount();
  16.             model.addColumn("ID");
  17.             model.addColumn("Estatus");
  18.             model.addColumn("Empleado");
  19.  
  20.             int[] anchos = {10, 50, 50};
  21.             for (int x = 0; x < columnas; x++) {
  22.                 jtAsignaciones.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  23.             }
  24.             while (rs.next()) {
  25.                 Object[] filas = new Object[columnas];
  26.                 for (int i = 0; i < columnas; i++) {
  27.                     filas[i] = rs.getObject(i + 1);
  28.                 }
  29.                 model.addRow(filas);
  30.             }
  31.         } catch (Exception e) {
  32.             JOptionPane.showMessageDialog(null, "Error al actualizar" + e);
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement