Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift and Postgres JDBC driver both intercept jdbc://postgresql connection string

I have a problem that I'm not quite sure how to solve: I have a web application (packaged as a war) and clients can configure which database they wish to point to. We support both PostgreSQL and Redshift (as well as others). JDBC4 drivers are loaded automatically, which is good. Here's the problem:

It appears that the Redshift JDBC driver will respond to the jdbc://postgresql connection string before the PostgreSQL one can. This causes JDBC errors when connecting to a PostgreSQL database.

I am specifying the driver name 'org.postgresql.Driver' as the driver for the datasource in my pom.xml, but i'm not sure how the spring JDBC templates are choosing the driver (unless it picks up the first handler).

Anyone else run into this sort of issue?

like image 283
Chris Knoll Avatar asked Aug 11 '15 20:08

Chris Knoll


People also ask

How does JDBC connect to redshift?

Before you can connect to your Amazon Redshift cluster from a SQL client tool, you need to know the JDBC URL of your cluster. The JDBC URL has the following format: jdbc:redshift:// endpoint : port / database . The fields of the preceding format have the following values. The protocol for the connection.

How do I find my redshift connection string?

To find the connection string for a clusterOn the navigation menu, choose Clusters, then choose the cluster name from the list to open its details. The JDBC URL and ODBC URL connection strings are available, along with additional details, in the General information section.


1 Answers

Another solution would be to add "OpenSourceSubProtocolOverride=true" to JDBC connection string for regular PostgreSQL connections.

Example:

jdbc:postgresql://localhost:5432/postgres?OpenSourceSubProtocolOverride=true  
like image 151
Vilis Avatar answered Sep 28 '22 01:09

Vilis