0

I am using Intellij IDEA in order to create my Web Application. I have created a project that has a package called com with four subpackages, one of which is called util. This package (util) contains a class called DatabaseUtility which gets a connection instance. Here is the code snippet:

public class DatabaseUtility {

    private static Connection connection = null;

    public static Connection getConnection() {
        if (connection != null)
            return connection;
        else {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/auction", "root", "password");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return connection;
        }

    }
}

When I debug this file I get thrown into the catch block with a java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error. I already added the mysql-connector-java-5.1.35-bin.jar to the External Libraries folder.

This exact code will work when this class is in the default package, but once I add it to a package, this error occurs. What am I missing?

0 Answers0