0

I have inherited a java project that uses jdbc drivers to connect to a postgreSQL database. We needed to update the database to version 10.3 (the most recent version currently available). Since upgrading the database, the project has been giving me errors that it is unable to connect to the database with the current jdbc drivers. How do I upgrade to the newest jdbc for postgreSQL? I have downloaded the most recent jar file from https://jdbc.postgresql.org/download.html, but I do not know how to use this file to upgrade my current jdbc drivers.

I am new to this and I need to know where to start. I am using intellij to build the project and I am running it on a linux machine.

ALec
  • 141
  • 3
  • 11

1 Answers1

9

If you're using maven, simply update the line in the pom.xml:

<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.2</version>
</dependency>

If you're using gradle, simply update the dependency in the build.gradle:

// https://mvnrepository.com/artifact/org.postgresql/postgresql
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'

If you aren't using any dependency management system, you can put the *.jar file into the classpath of your java project (ensure to delete the old one first!) - or you could simply rename the jar file like a_horse_with_no_name already suggested.

You can add the library to the class path like that:

In Intellij 13, it looks it's slightly different again. Here are the instructions for Intellij 13:

  • click on the Project view or unhide it by clicking on the "1: Project" button on the left border of the window or by pressing Alt + 1
  • find your project or sub-module and click on it to highlight it, then press F4, or right click and choose "Open Module Settings" (on IntelliJ 14 it became F12)
  • click on the dependencies tab
  • Click the "+" button on the right and select "Jars or directories..."
  • Find your path and click OK
  • In the dialog with "Choose Categories of Selected File", choose Classes (even if it's properties), press OK and OK again
  • You can now run your application and it will have the selected path in the class path

-> Source: https://stackoverflow.com/a/24843914/4934937

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
maio290
  • 6,440
  • 1
  • 21
  • 38
  • 1
    Great answer, one option you are missing is that the driver might be part of a tomcat or application server installation. – Mark Rotteveel Apr 24 '18 at 14:55