1 Reply Latest reply: Feb 7, 2013 12:24 PM by rukbat RSS

    How to get the sum value from a jtable column

      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();


      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
          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.