Foro de elhacker.net

Programación => Java => Mensaje iniciado por: soy_nicanor en 4 Marzo 2017, 14:45 pm



Título: agregar variables a columnas de jtable
Publicado por: soy_nicanor en 4 Marzo 2017, 14:45 pm

Columna 0 que es vendedor es String, Efectivo es Double , EC es double, y Dato es integer
Código
  1. String[] titulos = {"Vendedor","Efectivo ", "Efectivo Cja", "Dato"};
  2.        String[] registro = new String[4];
  3.        modelo = new DefaultTableModel(null, titulos);
  4.  
  5.        Connection cn = Conexion.getConnection();
  6.  
  7.        String sSQL = "SELECT usuario.usuario, reportediario.gananciaTotal, reportediario.efectivoBruto "+
  8.                "FROM reportediario " +
  9.                "INNER JOIN usuario ON usuario.id_us=reportediario.id_us ";                
  10.        try
  11.        {
  12.            Statement st = cn.createStatement();
  13.            ResultSet rs = st.executeQuery(sSQL);
  14.            int i=0;
  15.            while(rs.next())
  16.            {
  17.                registro[0] = rs.getString("usuario.usuario");
  18.                registro[1] = rs.getString("reportediario.gananciaTotal");
  19.                registro[2] = rs.getString("reportediario.efectivoBruto");
  20.                registro[3] = String.valueOf(i);
  21.                i++;
  22.                modelo.addRow(registro);              
  23.            }            
  24.            jTable1.setModel(modelo);//Buscador Princiapal          
  25.  
  26.            modelo = new DefaultTableModel(null, titulos) {
  27.                    public Class getColumnClass(int column) {
  28.                      if (column >= 0 && column <= getColumnCount())
  29.                        return getValueAt(0, column).getClass();
  30.                      else
  31.                        return Object.class;
  32.                    }
  33.                };
  34.        }
  35.        catch (SQLException ex){
  36.            JOptionPane.showMessageDialog(null, ex);
  37.        }
  38.  
  39.        TableRowSorter<TableModel> elQueOrdena = new TableRowSorter<TableModel>(modelo);      
  40.        jTable1.setRowSorter(elQueOrdena);
  41.  

Como podría agregar variables a las columnas.