如何在JTextPane中附加数据库的所有值

时间:2015-03-12 10:13:45

标签: java mysql

如何在TextPane中追加数据库的所有值。我正在为Billing流程制作软件,所以我想要从数据库中获取所有值来点击Button并使用TextPane附加但我遇到的问题是,当点击按钮时,只有一行附加了TextPane,而且没有附加。“

    PRODUCT|      |SIZE| |QUANTITY| |M.R.P.| |DIS| |AMOUNT|
    Apple Jucie    Large   1          30      0%     30
    Orange Jucie   Large   1          30      1%     29
    //Like that i want but only one line is coming

     public class BillingHandler implements ActionListener{
     public void actionPerformed(ActionEvent e){
     String itemname=e.getActionCommand();
       if(e.getSource().equals(ordTypeField)){
        ordertypeitem= ordTypeField.getSelectedItem().toString  ();           
        searchordertypeitem(ordertypeitem);

     }
  else if(itemname.equals("Order")){
          orderName=ordNameField.getSelectedItem().toString();
          //System.out.println("Name of Item :"+orderName);
          glasssizes=glasssizefield.getSelectedItem().toString();
         // System.out.println("Size of Item :"+glasssizes);
          noGlasses=noGlassField.getSelectedItem().toString();
          //System.out.println("no of Item :"+noGlasses);
          cash=remarkField.getSelectedItem().toString();
          //System.out.println("remark :"+cash); 
          orderitem();
         try{
             Class.forName(driver);
             con=DriverManager.getConnection(url,"root@localhost","root");
             Statement st=con.createStatement();
             String invoice="select * from ordertable where ord_no='"+ordField.getText()+"' ";
             ResultSet rs=st.executeQuery(invoice);
             while(rs.next()){
                 System.out.println(rs.getString("item_name"));
                  txtPane.setText(headerinfo
                 +"\nINV NO. "
                 +ordField.getText()
                 +"               "
                 +"Date: "
                 +dateField.getText()
                 +timeFiled.getText()
                 +"\nName: "
                 +cusField.getText()
                 +"               "
                 +"By Service: "
                 +empField.getText()
                 +"\n- - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                 +"\nPRODUCT|"
                 +"               "
                 +"|SIZE|"
                 +" "
                 +"|QUANTITY|"
                 +" "+"|M.R.P.|"
                 +" "+"|DIS|"
                 +" "+"|AMOUNT|"
                 +"\n- - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
                 +"\n"+rs.getString("item_name")// Here i want to print allvalue
                 +"\n"
                 +"                                  "
                 + rs.getString("size_item")")// Here i want to print allvalue

                 +"         "
                 + rs.getString("no_item")")// Here i want to print all value

                 +"                "
                 +rs.getString("mrp")")// Here i want to print all value

                 +"             "
                 +rs.getString("discount")")// Here i want to print all value

                 +"             "
                 +rs.getString("amount")")// Here i want to print all value

         );

             }
         }
         catch(SQLException ex){}
         catch(ClassNotFoundException ex){}
         catch(Exception ex){}
  }
 }
}

0 个答案:

没有答案