sql - Summing particular data in db column table and printing it to jtable -


i have newspaperorder table , wanted display sum of orders , subtotal of each newspaper listed in newspaper column in jtable.

database: enter image description here

so first, tried sum orders , total money earned specific newspaper , display newspapertable jtable.

         string x ='bulletin';          string sql = "select newspaper,price,sum(orders),sum(subtotal) newspaperorder newspaper='"+ x +"'";          pst = sqliteconn.preparestatement(sql);          rs = pst.executequery();             newspapertable.setmodel(dbutils.resultsettotablemodel(rs));          rs.close();           pst.close(); 

this works fine.

one data, jtable:

enter image description here

then, when attempted average orders , money earned of newspaper listed :

            templist = new arraylist<>();              string sql = "select * orderform";             pst = sqliteconn.preparestatement(sql);             rs = pst.executequery();                         while(rs.next()){                 templist.add(rs.getstring("newspaper"));             }             rs.close();              pst.close();             //system.out.println(templist);             for(int i=0; i<templist.size(); i++){                 string sql1 = "select newspaper,price,sum(orders),sum(subtotal) newspaperorder newspaper='"+ templist.get(i) +"'";                 pst = sqliteconn.preparestatement(sql1);                 rs = pst.executequery();                     newspapertable.setmodel(dbutils.resultsettotablemodel(rs));              }                 rs.close();                 pst.close(); 

i stored newspaper in array list, put working code in for loop loops equal size of templist array list.

the result displayed last newspaper in array list.

i assume table refreshed every loop & displayed average orders , total money earned per newspaper, how can display them @ same time in jtable?


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -