Advertisement
Metziop

Untitled

May 22nd, 2021
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. private void eficiencia() {
  2.         try {
  3.             DefaultTableModel model = new DefaultTableModel();
  4.             jtEficiencia.setModel(model);
  5.  
  6.             PreparedStatement ps = null;
  7.             ResultSet rs = null;
  8.             Connection conn;
  9.  
  10.             conn = MySQLConection.getConnection();
  11.  
  12.             String sql = "SELECT user, SUM(tiempoTotal) FROM pedidosempleado Where sucursal1='Matriz'";
  13.             ps = conn.prepareStatement(sql);
  14.             rs = ps.executeQuery();
  15.  
  16.             ResultSetMetaData rsm = rs.getMetaData();
  17.             int columnas = rsm.getColumnCount();
  18.             model.addColumn("Nombre");
  19.             model.addColumn("Tiempo de elaboracion en segundos");
  20.             int[] anchos = {20, 20};
  21.             for (int x = 0; x < columnas; x++) {
  22.                 jtEficiencia.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.         }
  33.  
  34.     }
  35.  
  36.     private void bono() {
  37.         String ganador = jtEficiencia.getValueAt(0, 0).toString();
  38.         txtBono.setText(ganador);
  39.  
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement