0

I have java project JavaProject4. In folder lib, I added file postgresql-42.2.2.jre7.jar (postgres driver). Next, I execute the following command:

Class.forName("org.postgresql.Driver").newInstance();

The command terminates with an error:

type: ClassNotFoundException detailMessage: "org.postgresql.Driver"

Question: how do I fix this error?

P.S. I'm a little versed in Java and the development environment of Netbeans. enter image description here

Anton
  • 163
  • 2
  • 14
  • 1
    i guess you have a dependency issue. You should check your dependencies. – Abdullah G Jul 05 '18 at 09:37
  • The project is created successfully. There are only such warnings: Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint: unchecked for details. – Anton Jul 05 '18 at 09:42
  • 1
    You do not have the Postgres JDBC driver in your classpath. Just by copying it into a "lib" directory does not necessarily add it to the classpath of your project. Did you add it to the project's libraries in the NetBeans project properties? –  Jul 05 '18 at 10:16
  • 1
    Unrelated, but: `Class.forName()` has not been necessary any more for a long time –  Jul 05 '18 at 10:18
  • Yes, I added the postgresql-42.2.2.jre7.zar library to the project properties (see screenshot). – Anton Jul 05 '18 at 11:12
  • I executed the commands according to the [link](https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/). The results of the commands: ..../lib/postgresql-42.2.2.jre7.jar .... – Anton Jul 05 '18 at 11:59
  • Download from this [link](https://jdbc.postgresql.org/download.html) postgresql-42.2.2.jre7.jar and added to the library and it all worked. – Anton Jul 05 '18 at 14:18

0 Answers0