0

我注意到,当我从创建的 GUI 向数据库发送数据时,它保存在那里,但是当我尝试调用它时,什么也没有发生。我还注意到,创建的结果集仅检索 java 连接到数据库时保存的记录,例如,如果在创建结果集时特定数据库表中有 500 条记录,则只能检索这 500 条记录,无需额外添加时可以检索记录。

我已经尝试了一切我迫切需要一些帮助或指出我正确的方向

这是负责检索记录的按钮的代码片段

JButton btncanel = new JButton("Submit");
btncanel.setBounds(820, 300, 80, 30);
btncanel.setFont(new Font("Times New Roman", Font.BOLD,12));
panel.add(btncanel);
btncanel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        if (scat3.getSelectedIndex() == 1) {

            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String FILE = "jdbc:odbc:Usermbj";
                Connection pcon = DriverManager.getConnection(FILE);
                java.sql.Statement pt = pcon.createStatement();
                ResultSet result = pt.executeQuery("SELECT * FROM Airlines2");

                while (result.next()) {
                    String LN = result.getString(3);
                    String FN = result.getString(4);
                    String COMP = result.getString(12);
                    int RAPnum = result.getInt(1);
                    String EH = result.getString(2);
                    String FRP = result.getString(5);
                    String ROD = result.getString(6);
                    int RS = result.getInt(7);
                    String OD = result.getString(8);
                    int OS = result.getInt(9);
                    String COOD =result.getString(10);
                    String AS = result.getString(11);

                    if ((scat2.getSelectedIndex() == 1 && crit.getText().equals(LN)) 
                        && (scat4.getSelectedIndex() == 1 && c.getText().equals(FN))) {

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }

                    if ((scat2.getSelectedIndex() == 1 && crit.getText().equals(LN))
                        && (c.getText().equals(""))) {

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender-----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }

                    if ((scat4.getSelectedIndex() == 1 && c.getText().equals(FN))
                        &&(crit.getText().equals(""))) {

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors-----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }
                }
            } catch(Exception g) {
                g.printStackTrace();
            }
        } else if (scat3.getSelectedIndex() == 2) {

            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String FILE = "jdbc:odbc:Usermbj";
                Connection pcon = DriverManager.getConnection(FILE);
                java.sql.Statement qt = pcon.createStatement();
                ResultSet result = qt.executeQuery("SELECT * FROM Concessionaire1");

                while (result.next()) {
                    String LN = result.getString(3);
                    String FN = result.getString(4);
                    String COMP = result.getString(12);
                    int RAPnum = result.getInt(2);
                    String EH = result.getString(1);
                    String FRP = result.getString(5);
                    String ROD = result.getString(6);
                    int RS = result.getInt(7);
                    String OD = result.getString(8);
                    int OS = result.getInt(9);
                    String COOD =result.getString(10);
                    String AS = result.getString(11);

                    if ((scat2.getSelectedIndex() == 1 && crit.getText().equals(LN))
                        && (scat4.getSelectedIndex() == 1 && c.getText().equals(FN))) {

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }

                    if ((scat2.getSelectedIndex() == 1 && crit.getText().equals(LN))
                        &&(c.getText().equals(""))){

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }

                    if ((scat4.getSelectedIndex() == 1 && c.getText().equals(FN))
                        &&(crit.getText().equals(""))) {

                        JOptionPane.showMessageDialog(null,
                            "Employment History----------" + " " + " " + EH + "\n\n"
                            + "Rap Code----------" + " " + " " + RAPnum + "\n\n"
                            + "First Name----------" + " " + " " + FN + "\n\n"
                            + "Last Name----------" + " " + " " + LN + "\n\n"
                            + "Finger Print Record----------" + " " + " " + FRP + "\n\n"
                            + "Re-Orientation Date----------" + " " + " " + ROD + "\n\n"
                            + "Re-Orientation Score----------" + " " + " " + RS + "\n\n"
                            + "Oreintation Date----------" + " " + " " + OD + "\n\n"
                            + "Orientation Score----------" + " " + " " + OS + "\n\n"
                            + "Coodintors----------" + " " + " " + COOD + "\n\n"
                            + "Applicant Gender----------" + " " + " " + AS + "\n\n"
                            + "Company----------" + " " + " " + COMP);

                        lnam.setText(LN);
                        fnam.setText(FN);
                        comp.setText(COMP);
                        empn.setText(String.valueOf(RAPnum));
                        scat.setText(EH);
                        fpr1.setText(FRP);
                        reod.setText(ROD);
                        reos.setText(String.valueOf(RS));
                        od.setText(OD);
                        os.setText(String.valueOf(OS));
                        cood.setText(COOD);
                        scat1.setText(AS);
                    }
                }
            } catch (Exception g) {
                g.printStackTrace();
            }
        }
    }
});
4

1 回答 1

1

首先,如果你打开一个连接或者创建一个语句,你应该在使用后关闭它,否则你很快就会耗尽资源。

其次,取决于您可能需要commit更改的数据库,否则事务可能会回滚并且数据会丢失。

于 2013-06-14T13:01:28.500 回答