Advertisement
Metziop

Untitled

May 31st, 2021
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1.  
  2.     //---------------------- haciendo la consulta-------------------//
  3.     private void Consulta() {
  4.  
  5.         try {
  6.             //----variables del metodo----//
  7.  
  8.             SimpleDateFormat dFormato = new SimpleDateFormat("yyyy-MM-dd");
  9.             String intervaloInicio = dFormato.format(jDCInicial.getDate());
  10.             String intervaloFinal = dFormato.format(jDCFechaFinal.getDate());
  11.             int fila = jTEmpleados.getSelectedRow();
  12.             String numEmpleado = jTEmpleados.getValueAt(fila, 0).toString();
  13.             //----terminan variables ----//
  14.             DefaultTableModel model = new DefaultTableModel();
  15.             jTRerporte.setModel(model);
  16.             PreparedStatement ps = null;
  17.             ResultSet rs = null;
  18.             Connection conn = MySQLConection.getConnection();
  19.             String SQL = "SELECT empleados.numEmpleado, empleados.user, empleados.puntoDeVenta, "
  20.                     + "count(pedidosempleado.idPedidoEmpleado) As conteo, "
  21.                     + "sum(pedidosempleado.tiempoTotal) AS tiempo, "
  22.                     + "sum(pedidosempleado.comision1)AS comision, "
  23.                     + "empleados.comision from empleados inner join pedidosempleado on empleados.numEmpleado=pedidosempleado.numeroEmpleado"
  24.                     + " where pedidosempleado.fechaFin between '" + intervaloInicio + "' AND '" + intervaloFinal + "' and empleados.numEmpleado='" + numEmpleado + "'";
  25.             ps = conn.prepareStatement(SQL);
  26.             rs = ps.executeQuery();
  27.             ResultSetMetaData rsm = rs.getMetaData();
  28.             int columnas = rsm.getColumnCount();
  29.             model.addColumn("idEmpleado");
  30.             model.addColumn("Usuario");
  31.             model.addColumn("Sucursal");
  32.             model.addColumn("Trabajos Realizados");
  33.             model.addColumn("Tiempo Trabajado");
  34.             model.addColumn("Comisiones");
  35.             model.addColumn("Comision");
  36.             int[] anchos = {2, 10, 20, 5, 10, 10, 10};
  37.             for (int x = 0; x < columnas; x++) {
  38.                 jTRerporte.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  39.             }
  40.             while (rs.next()) {
  41.                 Object[] filas = new Object[columnas];
  42.                 for (int i = 0; i < columnas; i++) {
  43.                     filas[i] = rs.getObject(i + 1);
  44.                 }
  45.                 model.addRow(filas);
  46.             }
  47.  
  48.         } catch (Exception e) {
  49.         }
  50.  
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement