dimanche 9 août 2015

Using SQLite file imported into java applicaiton

I'm working on a side-project and have decided to expand it's capabilities, but before I do anything I just want to improve the login function. I'm using an SQLite database file outside of the program for now, but I'm wanting to either integrate the file into the program, or find a way for the user to install both at once and the program use the directory it was installed to.

Here's what I have for the function:

        public void actionPerformed(ActionEvent arg0) {
                try{
                    String query = "select * from usernames where username=? and password=?";
                    PreparedStatement pst = dataConnection.prepareStatement(query);
                    pst.setString(1, textField_1.getText() );
                    pst.setString(2, passwordField.getText() );

                    ResultSet rs = pst.executeQuery();
                    int count = 0;
                    while (rs.next())
                    {
                        count++;
                    }
                    if(count == 1)
                    {
                        JOptionPane.showMessageDialog(null, "Login Successful, proceeding to functions list.");
                        dataConnection.close();
                        MainWindow.initializemain();
                        frmConsoleappReborn.setVisible(false);
                    }
                    else if (count > 1)
                    {
                        JOptionPane.showMessageDialog(null, "Contact developer and tell them the database is has duplicate values.");
                    }
                    else {
                        JOptionPane.showMessageDialog(null, "Username or password is incorrect. Please try again.");
                    }
                } catch(Exception e) {
                    JOptionPane.showMessageDialog(null, e);
                }
            }

All the best,

Groax

Aucun commentaire:

Enregistrer un commentaire