0

postgres is running at local host.

I am trying to get connected with db named sample from my java program.

And i placed my java program (JDBCExample.java)to connect db and jdbc driver in the same directory.

Now i execute the command

postgresconnection$ java -cp postgresql-9.3-1101.jdbc3.jar JDBCExample

Error: Could not find or load main class JDBCExample

How to fix this.

Siva Gnanam
  • 938
  • 2
  • 10
  • 26
  • This is a basic "how do I run a java program" question. The solution in this case is to get the classpath right. Read the question I linked to for a full explanation ... – Stephen C Mar 22 '14 at 11:00

1 Answers1

2

Try:

postgresconnection$ java -cp .:postgresql-9.3-1101.jdbc3.jar JDBCExample

Basically, you need to set the current dir in the classpath, java doesn't add it automatically.

Roberto
  • 8,586
  • 3
  • 42
  • 53