Sum of a column in a table and show it at the end of the summed column. JAVA NETBEANS

0

Hello everyone I have a difficulty with this code. what I want to do is that when the query is made to the BD to return it to the JTABLE since it is queried in a range defined by the user. I want the column 'amount' to be added automatically and at the end of that column appear the sum sum. They could give me some help or suggestion or some example I'll be very grateful

try{


     String desde1=txtDesde.getText();
    String hasta1=txtHasta.getText();
            Class.forName("com.mysql.jdbc.Driver");
            cn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost/","root","");
            ps=(PreparedStatement) cn.prepareStatement("select Item,Fecha,N_acta,Descripcion,"
                    + "Cantidad,Tipo_moneda,Condicion,Ape_pa,Ape_ma,"
                    + "Nombres,Nacionalidad,Tipo_doc,Dni,Direccion,Distrito,Provincia,Departamento,Jefe_sala,"
                    + "Modalidad from premio1"+ " WHERE N_acta BETWEEN'"+desde1+"'AND'"+hasta1+"'");

            rs=ps.executeQuery();
            rsm=(ResultSetMetaData) rs.getMetaData();
            ArrayList<Object[]>data=new ArrayList<>();
            while(rs.next()){
            Object[] rows=new Object[rsm.getColumnCount()];
            for(int i = 0; i < rows.length; i++ ){
            rows[i]=rs.getObject(i+1);
            }
            data.add(rows);
            }
            dtm=(DefaultTableModel)this.jReportePremio.getModel();
            for(int i=0; i<data.size();i++){
            dtm.addRow(data.get(i));
            }
}catch(ClassNotFoundException | SQLException e){
  JOptionPane.showMessageDialog(rootPane,e.getMessage());
}
    
asked by ronald 18.04.2018 в 23:21
source

0 answers