显示从数据库到JTextArea的元素

时间:2019-03-23 18:47:03

标签: java sql

我试图向JTextArea显示数据库中的一些信息。 我正在做的是能够将票据内的所有项目显示到此JtextArea中。但是我有问题。它只显示我帐单中的最后一个。 (并且我想展示所有这些内容)

这是我的代码(太糟糕了)

                 btn_AfficherFacture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea_facture.setText("");
            try {
                Connexion con = new Connexion();                 
                Statement stm = con.obtenirConnexion().createStatement();
                ResultSet recover_billID = stm.executeQuery( "select bill_id, bill_date, bill_name, payment_id from bill where bill_name = '" + comboBox_ListeNomFacture.getSelectedItem().toString() + "'");
                if(recover_billID.first()) {
                    Connexion con2 = new Connexion();
                    Statement stm2 = con.obtenirConnexion().createStatement();
                    ResultSet recover_bill = stm2.executeQuery( "select quantity, item_id from item_inBill where bill_id = '" + recover_billID.getString(1) + "'");
                    int total = com.heptathlonCLIENT.Fonction.prixTotal_facture(recover_billID.getInt(1));
                    while(recover_bill.next()) {
                        Connexion con3 = new Connexion();                 
                        Statement stm3 = con.obtenirConnexion().createStatement();
                        ResultSet recover_paymentMethod = stm3.executeQuery( "select payment_methode from payment_methode where mode_id = '" + recover_billID.getString(4) + "'");
                        while(recover_paymentMethod.next()) {
                            Connexion con4 = new Connexion();                 
                            Statement stm4 = con.obtenirConnexion().createStatement();
                            ResultSet recover_itemInfo = stm4.executeQuery( "select name, unit_price from item where item_id = '" + recover_bill.getString(2) + "'");
                            while(recover_itemInfo.next()) {

                                textArea_facture.setText(
                                        "///////////GOOD SHOP///////// \n"
                                        + "\n"
                                        + "bill date : " + recover_billID.getString(2) + "\n"
                                        + "Bill name : " + recover_billID.getString(3) + "\n"
                                        + "\n"
                                        + "Item name : " + recover_itemInfo.getString(1) + "\n"
                                        + "cost : " + recover_itemInfo.getString(2) + "\n"
                                        + "quantity : " + recover_bill.getString(1) + "\n"
                                        + "total cost : " + total + " euros \n"
                                        + ""
                                        + "Payment method : " + recover_paymentMethod.getString(1) + ""
                                        );                                                                      
                            }
                        }
                    }
                }
            } catch ( SQLException e1 ) {
                e1.printStackTrace();
            }
        }
     });

Here is the result

Thats my bill_item which countain the item into my bill 如您所见,有3个项目,但JTextArea中只有1个项目(item_id为6)

Connexion只是我的项目中的一门课,这使我能够连接到我的数据库。

私下

0 个答案:

没有答案