I have a method that inserts a record into Postgres DB and returns the identification field generated for the specified record. The problem is that if I included the Redshift driver in my POM file, this driver will be used instead of the Postgres driver, and the Redshift driver will not allow to return the identifier value.
The code:
try {
Class.forName( "org.postgresql.Driver" ).newInstance();
Connection connection = DriverManager.getConnection( "jdbc:postgresql://localhost:5433/postgres", "postgres", "password" );
Statement stmt = connection.createStatement();
stmt.execute( "insert into public.job ( job_name ) values ( 'test' )" , Statement.RETURN_GENERATED_KEYS );
ResultSet keyset = stmt.getGeneratedKeys();
if ( keyset.next() ) System.out.println( keyset.getLong( 1 ) );
}
catch ( Exception e ) {
e.printStackTrace();
}
When this POM is used, it works:
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
</dependencies>
When this POM is used, it does not work:
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>redshift.jdbc</artifactId>
<version>1.1.2.0002</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
</dependencies>
What does Java choose for the Redshift driver and not the Postgres driver?
(Redshift driver class path com.amazon.jdbc41.Driver , so I don't think this is a class conflict)
TIA
source
share