0
votes

I'm trying to compile and run java program with JDBC in terminal. I typed:

javac -sourcepath src:lib -cp lib/postgresql-9.2-1002.jdbc4.jar:lib/otherlibraries src/Database.java

Later I tried to run it:

java -cp src:lib/postgresql-9.2-1002.jdbc4.jar:otherlibraries Database

But when i tried to find driver:

try
{ Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException ex)
{...}

I got the error that no suitable driver was found, but when i run program in NetBeans I could connect to database. Unfortunately, I have to do it by terminal. What I did wrong?

  • Postgresql: 9.5.7
  • Java: 1.8
  • JDBC: postgresql-9.2-1002.jdbc4
1

1 Answers

0
votes

Check where the lib directory is.It should be in where your commands executed.

You can also do it whith absolute path

1.cd ${rootPath} (The root directory of your project)

2.java -cp .:${absoluteLibPath}/lib/* Database (use ".:" instead of "src")