This discussion is archived
1 Reply Latest reply: Feb 7, 2013 10:24 AM by rukbat RSS

How to get the sum value from a jtable column

989834 Newbie
Currently Being Moderated
i have a jtable which loads data from a database about items' details and the last column of the table is amount column.. it shows the price of item multiplied by item quantity.
and if i add many items and i want to get the totaol(sum) of all amounts to a textfeild..

here is my code i paste it from IDE
____________________________________________

Connection con = DB.itzMyConnection();
java.sql.Statement S = con.createStatement();

int Itmcd = Integer.parseInt( jTextField8.getText());


ResultSet r = S.executeQuery("Select * from items where ItemCode= '" jTextField8.getText() "'");
while (r.next()) {

String s1 = r.getString("ItemCode");
double unitPrice = Double.parseDouble(r.getString("Price"));
int Qty = Integer.parseInt(jTextField7.getText());

double amnt = unitPrice * Qty;

DefaultTableModel dft = (DefaultTableModel) jTable1.getModel();
Vector v1 = new Vector();
v1.add(s1);
v1.add(r.getString("ItemCategory"));
v1.add(r.getString("ItemName"));
v1.add(jTextField9.getText());
v1.add(Qty);
v1.add(unitPrice);
v1.add(amnt);

dft.addRow(v1);
}

}
here the amount columns total sum should be extracted out. help me pls
  • 1. Re: How to get the sum value from a jtable column
    rukbat Guru Moderator
    Currently Being Moderated
    You posted this exact same question to three different OTN forums, within minutes of each other. That is the same as if you were spamming these forums and is very poor etiquette.

    Do not do that. You pick the most likely location and place your post.
    You will either get a response or you won't get a response.

    These are user-to-user forums and others choose to respond as they wish.

    These Java forums are actively moderated and if you happen to choose an incorrect location, a post will be moved as a moderator might decide.

    We've removed the posts from Swing and from Java Programming.
    You are new here so we've left the post in the New-To-Java forum.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points