1

I am following this tutorial to make a program that interacts with the database. I am stuck at the last step where I run it. The given example is C:\test>java -cp c:\test\postgresql-8.3-603.jdbc4.jar;c:\test JDBCExample

I have both the .class file and the .jar for the JDBC in my home directory. I tried

java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB.class and I get "cannot exectue binary file"
I tried java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF/QueryDB and I get "no such file or directory"
I tried java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB and I get "JohnF is a directory"

I used chmod to set the file permissions to 777. How do I get this to run?

2 Answers 2

4

You are using semicolon as classpath separator - this will not work on Linux. Try replacing ";" with ":" in classpath and it should work.

Edit: explanation of what is happening here. In Linux, ";" is command separator. Your line of

java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar;/home/JohnF QueryDB

is really expanded into 2 executed one by one:

java -cp /home/JohnF/postgresql-9.2-1000.jdbc4.jar
/home/JohnF QueryDB

First one does nothing and successfully quits. Second tries to invoke /home/JohnF as executable, and this is really not an executable, but a directory!

Sign up to request clarification or add additional context in comments.

1 Comment

Note that if you double-quote the whole string it won't split it into two commands, but it'll still be wrong, because the classpath must be colon-separated on UNIX-like programs as per the introductory documentation for Java: docs.oracle.com/javase/tutorial/essential/environment/…
1

FIX: Use : instead of ;

WHY? The file-separator in *nix environment is ':' and not ';'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.