1
votes

Unable to connect to redshift using jdbc connection url.

My password has special characters eg: a(=b`git.

My url is jdbc:redshift://localhost:5439/trsanalytics?user=user1&password=a%28%3Db%60git

I am encoding the password and appending it. Still I get the following error

Amazon](500310) Invalid operation: password authentication failed for user

Sample code snippet

String encode_pwd = URLEncoder.encode(password,"UTF-8");
String fullUrl = url + "?user=" + username + "&password=" + encode_pwd;

DriverManager.getConnection(url)
1
first try print your password for testing that's right or not. - Omore
It is correct and it works when i add via properties. Properties props = new Properties(); props.setProperty("user", username); props.setProperty("password", password); executeQuery(DriverManager.getConnection(url, props)); works fine - nnc
try with encode_pwd.trim(); - Omore
If it works with properties, why not do it with properties? Giving password in the URL is a security issue, since the URL can be retrieved using connection.getMetaData().getURL(). - Andreas
@Osmore Try it why? - user207421

1 Answers

0
votes

A general solution for this is to not include the username and password as parameters in the URL string, but instead pass them as additional parameters in the getConnection call.

In Java, do:

// Don't URL encode the password
//String encode_pwd = URLEncoder.encode(password,"UTF-8");
// Don't include the user and password parameters in the url string
//String fullUrl = url + "?user=" + username + "&password=" + encode_pwd;

// Pass the parameters to the getConnection string
DriverManager.getConnection(url, user=username, password=password)

In R, using RJDBC, do:


conn <- dbConnect(
  driver,
  url,
  user=username,
  password=password)