0

so I am writing a programm that accesses a database but whenever i can the method Class.forName("org.postgresql.Driver); the ClassNotFoundException is thrown.

I have looked at every solution to this problem I could find, but nothing worked.

I hope you can help me with this.

Code:

public static void editDatabase(String[] values){
        Connection connect = null;
        Statement statement = null;
        ResultSet result = null;
        try {
            Class.forName("org.postgresql.Driver");
            connect = DriverManager.getConnection(values[0],values[1],values[2]);
            statement = connect.createStatement();
            result = statement.executeQuery("select * from Kunde");
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
1
  • 1
    The solution is always the same. The jar file of the postgresql driver must be added to the runtime classpath. Commented Mar 12, 2017 at 13:30

1 Answer 1

0

This problem means that your project does not load 'org.postgresql.Driver' at init. If you are using IntelliJ, you must add org.postgresql.Driver using 'Project Structure', it's located at your top right window. If you're not using IDE, I do recommend you to use one.

You could also use Maven and add 'org.postgresql.Driver' as a requirement for your project.

Bye.

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.