-1

I notice that when i sent data to the database from a GUI I have created it is save there,but when I try to recall it nothing is happening. I also notice that the result set which was created only retrieve records that were save when java made connection to the database,e.g. if say 500 records are in a particular database table when the result set was made only those 500 records can be retrieved no additional records when added can be retrieved.

I have try everything I am desperate need some help or point me in the right direction

Here is the code snippet for the button that is responsible to retrieved records

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();
            }
        }
    }
});
5
  • 3
    Anti-patterns festival :( Commented Jun 14, 2013 at 12:47
  • 8
    Something I noticed: not only are you reloading the driver every time a button is clicked (which is probably confusing the heck out of your program), you never CLOSE anything. Close your resultSets when you are done with them, as well as the entire connection. I would recommend loading the driver once, in main, and then create and use the connection only when needed, and then close the connection when you are done with it (right before you exit the event) Commented Jun 14, 2013 at 12:50
  • Which database do you use? Maybe it has issues saving the records to file (vg. HSQL or the like). Commented Jun 14, 2013 at 12:50
  • 1
    Some code formatting would be nice... Commented Jun 14, 2013 at 12:52
  • 1
    Please format your code before posting it here. It help others to read your question. Commented Jun 14, 2013 at 12:53

1 Answer 1

1

First of all, if you open a connection or create a statement, you should close it after using it, otherwise you will run out of resources soon enough.

Second, depending on the database you might have to commit the changes, otherwise the transaction might be rolled back and the data is lost.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.