Skip to content

Commit 95c86a8

Browse files
Trianz-Akshayritiktrianz
authored andcommitted
exception handling for jdbc
1 parent 55980c2 commit 95c86a8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/connection/GenericJdbcConnectionFactory.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.nio.charset.StandardCharsets;
3030
import java.sql.Connection;
3131
import java.sql.DriverManager;
32+
import java.sql.SQLException;
3233
import java.util.Map;
3334
import java.util.Properties;
3435
import java.util.regex.Matcher;
@@ -88,7 +89,19 @@ public Connection getConnection(final CredentialsProvider credentialsProvider)
8889
Class.forName(databaseConnectionInfo.getDriverClassName()).newInstance();
8990

9091
// create connection
91-
return DriverManager.getConnection(derivedJdbcString, this.jdbcProperties);
92+
Connection connection = null;
93+
try {
94+
connection = DriverManager.getConnection(derivedJdbcString, this.jdbcProperties);
95+
}
96+
catch (SQLException e) {
97+
if (e.getMessage().contains("Name or service not known")) {
98+
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
99+
}
100+
else if (e.getMessage().contains("Incorrect username or password was specified.")) {
101+
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidCredentialsException.toString()));
102+
}
103+
}
104+
return connection;
92105
}
93106

94107
private String encodeValue(String value)

athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/JdbcMetadataHandler.java

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ private Set<String> listDatabaseNames(final Connection jdbcConnection)
168168
}
169169
return schemaNames.build();
170170
}
171+
catch (RuntimeException ex) {
172+
throw new AthenaConnectorException("Invalid credentials was specified", new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidCredentialsException.toString()));
173+
}
171174
}
172175

173176
@Override

0 commit comments

Comments
 (0)