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.
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:
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
Post a Comment