comparison src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 225:5ddb1f20d5d5

Socket may also throw an UnknownHostException. Add it to MapiSocket.connect() and catch it in MonetConnection(Properties props).
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 03 May 2018 17:48:16 +0200 (2018-05-03)
parents 4572f0694fde
children 51e886d7f3b4 337a1292fe18
comparison
equal deleted inserted replaced
224:ea729e0cf24d 225:5ddb1f20d5d5
10 10
11 import java.io.File; 11 import java.io.File;
12 import java.io.IOException; 12 import java.io.IOException;
13 import java.net.SocketException; 13 import java.net.SocketException;
14 import java.net.SocketTimeoutException; 14 import java.net.SocketTimeoutException;
15 import java.net.UnknownHostException;
15 import java.sql.CallableStatement; 16 import java.sql.CallableStatement;
16 import java.sql.Connection; 17 import java.sql.Connection;
17 import java.sql.DatabaseMetaData; 18 import java.sql.DatabaseMetaData;
18 import java.sql.PreparedStatement; 19 import java.sql.PreparedStatement;
19 import java.sql.ResultSet; 20 import java.sql.ResultSet;
246 } 247 }
247 248
248 // check mandatory input arguments 249 // check mandatory input arguments
249 if (hostname == null || hostname.isEmpty()) 250 if (hostname == null || hostname.isEmpty())
250 throw new IllegalArgumentException("Missing or empty host name"); 251 throw new IllegalArgumentException("Missing or empty host name");
251 if (port <= 0) 252 if (port <= 0 || port > 65535)
252 throw new IllegalArgumentException("Invalid port number. It should not be " + (port < 0 ? "negative" : "0")); 253 throw new IllegalArgumentException("Invalid port number: " + port + ". It should not be " + (port < 0 ? "negative" : (port > 65535 ? "larger than 65535" : "0")));
253 if (username == null || username.isEmpty()) 254 if (username == null || username.isEmpty())
254 throw new IllegalArgumentException("Missing or empty user name"); 255 throw new IllegalArgumentException("Missing or empty user name");
255 if (password == null || password.isEmpty()) 256 if (password == null || password.isEmpty())
256 throw new IllegalArgumentException("Missing or empty password"); 257 throw new IllegalArgumentException("Missing or empty password");
257 if (language == null || language.isEmpty()) { 258 if (language == null || language.isEmpty()) {
303 out = server.getWriter(); 304 out = server.getWriter();
304 305
305 String error = in.waitForPrompt(); 306 String error = in.waitForPrompt();
306 if (error != null) 307 if (error != null)
307 throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001"); 308 throw new SQLNonTransientConnectionException((error.length() > 6) ? error.substring(6) : error, "08001");
309 } catch (UnknownHostException e) {
310 throw new SQLNonTransientConnectionException("Unknown Host (" + hostname + "): " + e.getMessage(), "08006");
308 } catch (IOException e) { 311 } catch (IOException e) {
309 throw new SQLNonTransientConnectionException("Unable to connect (" + hostname + ":" + port + "): " + e.getMessage(), "08006"); 312 throw new SQLNonTransientConnectionException("Unable to connect (" + hostname + ":" + port + "): " + e.getMessage(), "08006");
310 } catch (MCLParseException e) { 313 } catch (MCLParseException e) {
311 throw new SQLNonTransientConnectionException(e.getMessage(), "08001"); 314 throw new SQLNonTransientConnectionException(e.getMessage(), "08001");
312 } catch (MCLException e) { 315 } catch (MCLException e) {