-1

My program is a simulated online shopping system. The program displays a login screen when it is run, and the user can click the "Forgot Password" button if they do not remember their login. Upon clicking this button, the program opens a frame where the user can enter their email address. When the user enters this email address and hits the "Send Password Recovery Email", a message dialog is supposed to show up informing the user that the email either was successfully sent (if the user has entered in the email address that is actually associated with their ID) or was not sent (if the address the user entered either does not exist in the database or all or is tied to a different user). However, no message dialog pops up when I run the program, and I cannot figure out why. No exception is returned - the program just refuses to display the dialog.

Here is the code for all the relevant parts of the program. Sorry for providing so much code, but since the program isn't returning an exception, I have no idea whatsoever where the code that is causing the program to malfunction is. There are other parts to the program, but they are not directly relevant to the "forgot password" screen.

Application:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class Application {

    private static Application instance;   // Singleton pattern

    private static boolean checkEmail = false;

    private static String email;

    public static Application getInstance() {
        if (instance == null) {
            instance = new Application();
        }
        return instance;
    }
    // Main components of this application

    private Connection connection;

    public Connection getConnection() {
        return connection;
    }

    public static void setCheckEmail() {
        checkEmail = true;
    }

    public static void setEmail(String theEmail) {
        email = theEmail;
    }

    private DataAdapter dataAdapter;

    private User currentUser = null;

    public void setCurrentUser(User user) {
        this.currentUser = user;
    }

    public User getCurrentUser() {
        return currentUser;
    }

    // Create the Product View and Controller here!

    private ProductView productView = new ProductView();

    private CheckoutScreen checkoutScreen = new CheckoutScreen();

    private MainScreen mainScreen = new MainScreen();

    public MainScreen getMainScreen() {
        return mainScreen;
    }

    public ProductView getProductView() {
        return productView;
    }

    public CheckoutScreen getCheckoutScreen() {
        return checkoutScreen;
    }

    public LoginScreen loginScreen = new LoginScreen();

    public LoginScreen getLoginScreen() {
        return loginScreen;
    }

    public LoginController loginController; // = new LoginController(loginScreen, dataAdapter);

    private ProductController productController;

    public ProductController getProductController() {
        return productController;
    }

    private CheckoutController checkoutController;

    public CheckoutController getCheckoutController() {
        return checkoutController;
    }

    public DataAdapter getDataAdapter() {
        return dataAdapter;
    }

    private ForgotPasswordScreen forgotPasswordScreen = new ForgotPasswordScreen();

    public ForgotPasswordScreen getForgotPasswordScreen() {
        return forgotPasswordScreen;
    }

    private void initializeDatabase(Statement stmt) throws SQLException { // CHANGE: Added initialization code
        // create the tables and insert sample data here!

        stmt.execute("create table Product (ProductID int PRIMARY KEY, ProductName char(30), Price double, Quantity double);");
        stmt.execute("create table Orders (ProductID int PRIMARY KEY, ProductName char(30), Price double, Quantity double);");
        stmt.execute("create table OrderLine (OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity double, Cost double, PRIMARY KEY (ProductID, OrderID);");
        stmt.execute("create table User (UserID INT NOT NULL, UserName CHAR(30) NOT NULL, Password CHAR(30) NOT NULL, DisplayName CHAR(30), IsManager BOOL DEFAULT FALSE, PRIMARY KEY(UserID));");
        stmt.execute("create table sqlite_sequence (name, seq);");
        stmt.execute("INSERT INTO Product VALUES (1, 'Apple', 1.0, 257.0), (2, 'Chair', 100.0, 38.0), (3, 'Smartphone', 699.99, 486.0), (4, 'T-shirt', 20.0, 244.0), (5, 'TV', 250.0, 43.0);");
        stmt.execute("INSERT INTO User VALUES (1, 'admin', 'password', 'Admin', TRUE);");


    }

    private void initializeEmailList(Statement stmt) throws SQLException {
        stmt.execute("CREATE TABLE Email (Email CHAR(30) NOT NULL, UserID int NOT NULL);");
        stmt.execute("INSERT INTO Email VALUES('admin@example.com', 1);");
    }

    private Application() {
        // create SQLite database connection here!
        try {
            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:store.db");
            Statement stmt = connection.createStatement();
            if (!stmt.executeQuery("select * from product").next()) // product table do not exist
                initializeDatabase(stmt);
            if (!stmt.executeQuery("select * from email").next()) // product table do not exist
                initializeEmailList(stmt);
            if(checkEmail == true) {
                Statement stmt2 = connection.createStatement();
                ResultSet resultSet = stmt2.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
                if (!resultSet.next())
                    JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
                else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
                else JOptionPane.showMessageDialog(null, "Email sent!");
                //Application.getInstance().checkEmail(email);
                checkEmail = false;
            }


        }
        catch (ClassNotFoundException ex) {
            System.out.println("SQLite is not installed. System exits with error!");
            System.exit(1);
        }

        catch (SQLException ex) {
            System.out.println("SQLite database is not ready. System exits with error!" + ex.getMessage());

            System.exit(2);
        }

        // Create data adapter here!
        dataAdapter = new DataAdapter(connection);

        productController = new ProductController(productView, dataAdapter);

        checkoutController = new CheckoutController(checkoutScreen, dataAdapter);

        loginController = new LoginController(loginScreen, dataAdapter);
    }


    public static void main(String[] args) {
        Application.getInstance().getLoginScreen().setVisible(true);
    }
}

ForgotPasswordController:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class ForgotPasswordController implements ActionListener {
    private ForgotPasswordScreen forgotPasswordScreen;

    public ForgotPasswordController(ForgotPasswordScreen forgotPasswordScreen) {
        this.forgotPasswordScreen = forgotPasswordScreen;
        this.forgotPasswordScreen.getSendEmail().addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == forgotPasswordScreen.getSendEmail()) {
            String email = forgotPasswordScreen.getEmailAddress().getText().trim();
            Application.setEmail(email);
            Application.setCheckEmail();
            /*Connection forgotPasswordConnection = Application.getInstance().getConnection();
            Statement stmt = forgotPasswordConnection.createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
            else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
            else JOptionPane.showMessageDialog(null, "Email sent!");*/
            //Application.getInstance().checkEmail(email);
            Application application = Application.getInstance();
        }
    }
}

ForgotPasswordScreen:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ForgotPasswordScreen extends JFrame {
    private JTextField emailAddress = new JTextField(30);

    private JButton sendEmail = new JButton("Send Password Recovery Email");

    public JButton getSendEmail() {
        return sendEmail;
    }

    public JTextField getEmailAddress() {
        return emailAddress;
    }

    public ForgotPasswordScreen() {
        this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(400, 200);

        JPanel panelForgotPasswordScreen = new JPanel();

        JLabel emailAddressLabel = new JLabel("Email address:");

        panelForgotPasswordScreen.add(emailAddressLabel);
        panelForgotPasswordScreen.add(emailAddress);

        this.getContentPane().add(panelForgotPasswordScreen);

        JPanel panelSendEmailButton = new JPanel();
        panelSendEmailButton.add(sendEmail);

        this.getContentPane().add(sendEmail);

    }
}

LoginController:

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginController implements ActionListener {
    private LoginScreen loginScreen;
    private DataAdapter dataAdapter;


    public LoginController(LoginScreen loginScreen, DataAdapter dataAdapter) {
        this.loginScreen = loginScreen;
        this.dataAdapter = dataAdapter;
        this.loginScreen.getBtnLogin().addActionListener(this);
        this.loginScreen.getBtnForgotPassword().addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == loginScreen.getBtnLogin()) {
            String username = loginScreen.getTxtUserName().getText().trim();
            String password = loginScreen.getTxtPassword().getText().trim();

            System.out.println("Login with username = " + username + " and password = " + password);
            User user = dataAdapter.loadUser(username, password);

            if (user == null) {
                JOptionPane.showMessageDialog(null, "This user does not exist!");
            }
            else {
                Application.getInstance().setCurrentUser(user);
                this.loginScreen.setVisible(false);
                Application.getInstance().getMainScreen().setVisible(true);
            }
        }
        if(e.getSource() == loginScreen.getBtnForgotPassword()) {
            Application.getInstance().getForgotPasswordScreen().setVisible(true);
        }
    }
}

LoginScreen:

import javax.swing.*;
import java.awt.*;

public class LoginScreen extends JFrame {
    private JTextField txtUserName = new JTextField(10);
    private JTextField txtPassword = new JTextField(10);
    private JButton    btnLogin    = new JButton("Login");
    private JButton btnForgotPassword = new JButton("Forgot Password"); //CHANGE: Added a mechanism for the user to recover a forgotten password

    public JButton getBtnLogin() {
        return btnLogin;
    }

    public JTextField getTxtPassword() {
        return txtPassword;
    }

    public JTextField getTxtUserName() {
        return txtUserName;
    }

    public JButton getBtnForgotPassword() {
        return btnForgotPassword;
    }

    public LoginScreen() {


        this.setSize(300, 400);
        this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));

        this.getContentPane().add(new JLabel ("Store Management System"));

        JPanel panelUserName = new JPanel();
        panelUserName.add(new JLabel("Username:"));
        panelUserName.add(txtUserName);

        this.getContentPane().add(panelUserName);

        JPanel panelPassword = new JPanel();
        panelPassword.add(new JLabel("Password:"));
        panelPassword.add(txtPassword);

        this.getContentPane().add(panelPassword);

        JPanel panelLogin = new JPanel();
        panelLogin.setAlignmentX(Component.CENTER_ALIGNMENT); //CHANGE: Centered the login and "forgot password" buttons
        panelLogin.add(btnLogin);

        JPanel panelForgotPassword = new JPanel();
        panelLogin.setAlignmentX(Component.CENTER_ALIGNMENT);
        panelForgotPassword.add(btnForgotPassword);

        this.getContentPane().add(panelLogin);
        this.getContentPane().add(panelForgotPassword);
    }
}

EDIT: Following MadProgrammer's advice, I removed the code that tests the validity of the email address inputted by the user from the Application class and added it to my ForgotPasswordController class inside the actionPerformed method; however, I am now receiving a new error: "unreported exception java.sql.SQLException; must be caught or declared to be thrown".

Adding "throws SQLException" to the actionPerformed method does not work in diagnosing the problem because the method it is overriding does not include "throws SQLException"; doing this merely creates a new error saying "java: actionPerformed(java.awt.event.ActionEvent) in ForgotPasswordController cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener overridden method does not throw java.sql.SQLException".

Here is the new code for my actionPerformed method:

@Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == forgotPasswordScreen.getSendEmail()) {
            String email = forgotPasswordScreen.getEmailAddress().getText().trim();
            //Application.setEmail(email);
            //Application.setCheckEmail();
            /*Connection forgotPasswordConnection = Application.getInstance().getConnection();
            Statement stmt = forgotPasswordConnection.createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
            else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
            else JOptionPane.showMessageDialog(null, "Email sent!");*/
            //Application.getInstance().checkEmail(email);
            //Application application = Application.getInstance();
            Connection connection = DriverManager.getConnection("jdbc:sqlite:store.db");
            Statement stmt = connection.createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
            else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
            else JOptionPane.showMessageDialog(null, "Email sent!");
        }
    }

EDIT 2: I have now removed most of the above code from my ForgotPasswordController method and created a new method within my Application class called emailValidityChecker:

public void emailValidityChecker(String emailAddress, String username) throws SQLException {
            Statement stmt2 = connection.createStatement();
            ResultSet resultSet = stmt2.executeQuery("SELECT * from User WHERE UserName = " + username);
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "No account has been registered with this username!");
            else {
                int userID = resultSet.getInt(1);
                Statement stmt3 = connection.createStatement();
                ResultSet resultSet2 = stmt3.executeQuery("SELECT * from Email where UserID = " + userID);
                String correspondingEmail = resultSet2.getString(1);
                if (!resultSet2.next())
                    JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
                else if (!correspondingEmail.equals(emailAddress))
                    JOptionPane.showMessageDialog(null, "Incorrect email!");
                else JOptionPane.showMessageDialog(null, "Email sent!");
            }
        }

I have also changed my actionPerformed method in my ForgotPasswordController class so that it now looks like this:

@Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == forgotPasswordScreen.getSendEmail()) {
            String email = forgotPasswordScreen.getEmailAddress().getText().trim();
            String username = forgotPasswordScreen.getUsername().getText().trim();
            //Application.setEmail(email);
            //Application.setCheckEmail();
            /*Connection forgotPasswordConnection = Application.getInstance().getConnection();
            Statement stmt = forgotPasswordConnection.createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
            else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
            else JOptionPane.showMessageDialog(null, "Email sent!");*/
            //Application.getInstance().checkEmail(email);
            //Application application = Application.getInstance();
            /*Connection connection = DriverManager.getConnection("jdbc:sqlite:store.db");
            Statement stmt = connection.createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
            if (!resultSet.next())
                JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
            else if (resultSet.getString(1) != email) JOptionPane.showMessageDialog(null, "Incorrect email!");
            else JOptionPane.showMessageDialog(null, "Email sent!");*/
            Application.getInstance().emailValidityChecker(email, username);
        }
    }

Unfortunately, I am experiencing the same error I was describing in my previous edit. I am still getting the message "java: unreported exception java.sql.SQLException; must be caught or declared to be thrown" on the line "Statement stmt2 = connection.createStatement();", and adding "throws SQLException" doesn't help because I then got the exact same exception but on the last line of my actionPerformed method in my ForgotPasswordController class. I could add a try-catch block in my emailValidityChecker method, but this still wouldn't tell me anything about why I am receiving an SQL exception.

  • If `Application.getInstance()` has been called before your "check email" workflow, subsequent calls to `getInstance` WILL NOT create a new instance of `Application`, therefore, it will NEVER try and execute the "forgotten" password workflow. Instead, you should have a "forgotPassword" method, into which you pass your email address and it would run the workflow independently - and `Application` shouldn't be display dialogs, that's the responsibility of the caller – MadProgrammer Mar 09 '23 at 01:02
  • I would also do some research into the [singleton pattern](https://www.google.com/search?q=java+singlton+pattern&rlz=1C5GCEM_enAU1020AU1020&oq=java+singlton+pattern&aqs=chrome..69i57.3255j0j7&sourceid=chrome&ie=UTF-8) in Java, as how you're doing it isn't the recommend way (hint, anything that isn't making use of a `enum` is probably doing it wrong) – MadProgrammer Mar 09 '23 at 01:03
  • I would also recommend making use of [`PreparedStatement`](https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) – MadProgrammer Mar 09 '23 at 01:04
  • And you could save yourself some trouble by using [`create table if not exists`](https://www.google.com/search?q=sqlite+create+table+if+not+exists&rlz=1C5GCEM_enAU1020AU1020&oq=sqlite+crea&aqs=chrome.1.69i57j69i59.8444j0j7&sourceid=chrome&ie=UTF-8) – MadProgrammer Mar 09 '23 at 01:08
  • @MadProgrammer I took your advice and removed the code that checked the validity of the inputted email from the constructor of the Application class. I inserted new code into the actionPerformed method in my ForgotPasswordController class, but now I'm getting an SQLException. My IDE is not saying what specifically is wrong with my code; it simply says "java: unreported exception java.sql.SQLException; must be caught or declared to be thrown". If add "throws SQLException" to actionPerformed, it throws a new error saying... (message continued in next comment) – StanAtkinson Mar 09 '23 at 01:32
  • ... "java: actionPerformed(java.awt.event.ActionEvent) in ForgotPasswordController cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener overridden method does not throw java.sql.SQLException". I'll put the new code I wrote in an edit of my original post. – StanAtkinson Mar 09 '23 at 01:33
  • *"unreported exception java.sql.SQLException"* That's because many of the JDBC methods throw `SQLException`, which you should need to report – MadProgrammer Mar 09 '23 at 02:05
  • `actionPerformed` is defined by `ActionListener`, it doesn't throw any exceptions, you will nee to add a `try-catch` to catch `SQLException` within the `actionPerformed` method – MadProgrammer Mar 09 '23 at 02:06
  • `if (resultSet.getString(1) != email)` will almost certainly fail. See https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java. – VGR Mar 09 '23 at 04:06

1 Answers1

0

Let's strip away some of the noise and have a close look at this...

public class Application {

    private static Application instance;   // Singleton pattern

    private static boolean checkEmail = false;
    private static String email;

    public static Application getInstance() {
        if (instance == null) {
            instance = new Application();
        }
        return instance;
    }

    public Connection getConnection() {
        return connection;
    }

    private Application() {
        // create SQLite database connection here!
        try {
            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:store.db");
            Statement stmt = connection.createStatement();
            if (!stmt.executeQuery("select * from product").next()) // product table do not exist
            {
                initializeDatabase(stmt);
            }
            if (!stmt.executeQuery("select * from email").next()) // product table do not exist
            {
                initializeEmailList(stmt);
            }
            if (checkEmail == true) {
                Statement stmt2 = connection.createStatement();
                ResultSet resultSet = stmt2.executeQuery("SELECT * from Email WHERE UserID = " + Application.getInstance().getCurrentUser().getUserID());
                if (!resultSet.next()) {
                    JOptionPane.showMessageDialog(null, "This email does not belong to any registered user!");
                } else if (resultSet.getString(1) != email) {
                    JOptionPane.showMessageDialog(null, "Incorrect email!");
                } else {
                    JOptionPane.showMessageDialog(null, "Email sent!");
                }
                //Application.getInstance().checkEmail(email);
                checkEmail = false;
            }

        } catch (ClassNotFoundException ex) {
            System.out.println("SQLite is not installed. System exits with error!");
            System.exit(1);
        } catch (SQLException ex) {
            System.out.println("SQLite database is not ready. System exits with error!" + ex.getMessage());

            System.exit(2);
        }

        // Create data adapter here!
        dataAdapter = new DataAdapter(connection);

        productController = new ProductController(productView, dataAdapter);

        checkoutController = new CheckoutController(checkoutScreen, dataAdapter);

        loginController = new LoginController(loginScreen, dataAdapter);
    }

    public static void main(String[] args) {
        Application.getInstance().getLoginScreen().setVisible(true);
    }
}

So, in the main method you call Application.getInstance().getLoginScreen().setVisible(true);

This will:

  • Create a new instance of Application (in getInstance)
  • The constructor will initialise the database and other internal state, but since checkEmail is false by default, it won't execute that workflow
  • Display the login screen

Eventually, we find ourselves here...

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == forgotPasswordScreen.getSendEmail()) {
        String email = forgotPasswordScreen.getEmailAddress().getText().trim();
        Application.setEmail(email);
        Application.setCheckEmail();
        Application application = Application.getInstance();
    }
}

Now, the problem with this is, when you call Application.getInstance(), you will get back the instance which was previously create (way back in when main was called, kind of the point of a singleton), so the constructor is never called.

Instead, you should have a dedicated method for handling forgotten passwords, maybe something more like...

public enum Application {
    INSTANCE;

    private Connection connection;
    private User currentUser = null;

    private Application() {
        // Setup and initialisation
    }

    public Connection getConnection() {
        return connection;
    }

    // Not sure this makes sense to me, unless the authentication
    // workflow is seperate from the Application, I'd probably not
    // allow the user to be set here, but that's me
    public void setCurrentUser(User user) {
        this.currentUser = user;
    }

    public User getCurrentUser() {
        return currentUser;
    }

    public void recoverAccount(String email) throws Exception {
        try (PreparedStatement stmt = connection.prepareStatement("SELECT * from Email WHERE UserID = ?")) {
            // How do you get the current userId for a user whose not logged in?
            // I smell a NullPointerException in your future
            stmt.setInt(1, getCurrentUser().getUserID());
            try (ResultSet rs = stmt.executeQuery()) {
                // Personally, I'd throw customised exceptions here, as they are
                // easier to deal with
                if (!resultSet.next()) {
                    throw Exception("This email does not belong to any registered user!");
                } else if (resultSet.getString(1) != email) {
                    throw Exception("Incorrect email!");
                }
            }
        }
    }
    // Other functionality not implemented
}

And then you'd simply call Application.INSTANCE.recoverAccount(someEmailAddress); ... but just beware, this will throw an Exception

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I ended up adding a new text field where the user could enter their username to the ForgotPasswordScreen. Further, I added a new method called "emailValidityChecker" to my Application class, which was supposed to check the validity of the entered email by first matching the username to a userID, then matching the userID to an email address. If both of these matches are able to be made and the email address stored in the database matches that entered by the user, a dialog box will pop up stating that an email was successfully sent. (message continued in next comment) – StanAtkinson Mar 09 '23 at 02:19
  • Otherwise, one of a variety of dialog boxes will show up indicating that an email address could not be found in the database that matches the user's input. However, when trying to compile my program, the program returns an SQLException error with the text "unreported exception java.sql.SQLException; must be caught or declared to be thrown". Of course, to prevent this particular message from appearing I could implement try-catch blocks into my code, but that still wouldn't tell me why I am actually getting the exception. (message continued in next comment) – StanAtkinson Mar 09 '23 at 02:23
  • I will update my original post with the new code I wrote. The particular line that seems to be causing the error seems to be "Statement stmt2 = connection.createStatement();" - where the program tries to create a statement using the connection established. I have no idea why this would be happening. – StanAtkinson Mar 09 '23 at 02:26
  • You're going to have to handle the error and the best place is in the `actionPerformed` method, as this is what called the method. Again, I'd refrain from displaying dialogs inside the `emailValidityChecker` method, that's not it's responsibility – MadProgrammer Mar 09 '23 at 08:03