Advertisement
Metziop

Untitled

May 22nd, 2021
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1.  // -------------- Metodo para calcular las comisiones -------------///
  2.     private void actualizarTabla2(String user) {
  3.  
  4.         try {
  5.             DefaultTableModel model = new DefaultTableModel();
  6.             jtComisiones.setModel(model);
  7.             jtComisiones.setAutoCreateRowSorter(true);
  8.             PreparedStatement ps = null;
  9.             ResultSet rs = null;
  10.             Connection conn;
  11.  
  12.             conn = MySQLConection.getConnection();
  13.  
  14.             String sql = "SELECT user, SUM(comision1) FROM pedidosempleado Where sucursal1='Matriz'";
  15.             ps = conn.prepareStatement(sql);
  16.             rs = ps.executeQuery();
  17.  
  18.             ResultSetMetaData rsm = rs.getMetaData();
  19.             int columnas = rsm.getColumnCount();
  20.             model.addColumn("Nombre");
  21.             model.addColumn("Comision");
  22.             int[] anchos = {20, 20};
  23.             for (int x = 0; x < columnas; x++) {
  24.                 jtComisiones.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  25.             }
  26.             while (rs.next()) {
  27.                 Object[] filas = new Object[columnas];
  28.                 for (int i = 0; i < columnas; i++) {
  29.                     filas[i] = rs.getObject(i + 1);
  30.                 }
  31.                 model.addRow(filas);
  32.             }
  33.         } catch (Exception e) {
  34.         }
  35.  
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement