Loading the postgreSQL JDBC driver

后端 未结 3 1028
我寻月下人不归
我寻月下人不归 2021-01-22 20:48

I am trying to load a JDBC postgreSQL driver for a Java program. I know this is all over the Internet. I have tried many solutions, but none of them have worked for me.

相关标签:
3条回答
  • 2021-01-22 21:27

    On Linux execute following:

    javac -cp '.:postgresql-9.1-901.jdbc4.jar' postgresjavatest.java

    java -cp '.:postgresql-9.1-901.jdbc4.jar' postgresjavatest

    It will jdbc drivers for you. make sure jar file is on same location

    0 讨论(0)
  • 2021-01-22 21:36

    Firstly you need to mention the package names using . instead of / while running the java program:

    Go to your classes directory and run JDBCExample as :

    java com.freire.test.JDBCExample
    

    But it will now cry for the postgres driver class not found because postgres jar is missing in the classpath.So you need to use the classpath option while running the program and add your postgres jar to the classpath:

    for windows:

    java -cp .;../lib/postgresql-9.2-1003.jdbc3.jar com.freire.test.JDBCExample
    

    for linux:

    java -cp .:../lib/postgresql-9.2-1003.jdbc3.jar com.freire.test.JDBCExample
    
    0 讨论(0)
  • 2021-01-22 21:47

    You need to ensure that the postgresql-9.2-1003.jdbc3.jar is within the class path when you compile and run the program

    Try using

    javac -cp lib/postgresql-9.2-1003.jdbc3.jar -d classes/ src/com/freire/test/JDBCExample.java
    

    to compile the application and

    java -cp lib/postgresql-9.2-1003.jdbc3.jar;./classes com.freire.test.JDBCExample
    

    to run it...

    nb As Juned has pointed, technically, you don't need the lib/postgresql-9.2-1003.jdbc3.jar references in the classpath, but consider it an demonstration of how to included compile time dependencies within the complication process ;)

    0 讨论(0)
提交回复
热议问题