List of utility methods to do JDBC Connection Create
Connection | getConnection(final String driverName, final String driverUrl, final String userName, final String password) Gets the connection. Class.forName(driverName);
return DriverManager.getConnection(driverUrl, userName, password);
|
Connection | getConnection(final String url) get Connection try { return DriverManager.getConnection(url); } catch (SQLException e) { return null; |
Connection | getConnection(final String url, final String username, final String password, final String driverClass) get Connection Class.forName(driverClass);
return DriverManager.getConnection(url, username, password);
|
Connection | getConnection(Properties pro) get Connection Class.forName(pro.getProperty("jdbc.driver")); return DriverManager.getConnection(pro.getProperty("jdbc.url"), pro.getProperty("jdbc.username"), pro.getProperty("jdbc.password")); |
Connection | getConnection(Properties prop) get Connection Connection conn = null; try { if (conn == null) { conn = DriverManager.getConnection("jdbc:phoenix:yahoo005.nicl.cs.duke.edu:2181", prop); ResultSet rs = conn.prepareStatement("select count(*) from nation").executeQuery(); while (rs.next()) { System.out.println("row count " + rs.getInt(1)); System.out.println("Connection established successfully"); } catch (SQLException e) { System.err.println("Error in getting zookeeper connection"); e.printStackTrace(); return conn; |
Connection | getConnection(Properties properties) get Connection Class.forName((String) properties.get(DRIVER_NAME));
return DriverManager.getConnection((String) properties.get(JDBC_URL), properties);
|
Connection | getConnection(String dbName) get Connection try { Class.forName(DRIVER); } catch (ClassNotFoundException e) { e.printStackTrace(); try { return DriverManager.getConnection(PROTOCOL + dbName + ";create=true"); } catch (SQLException e) { ... |
Connection | getConnection(String dbUrl, String dbUser, String dbPassword) get Connection try { final Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); conn.setAutoCommit(true); return conn; } catch (Exception e) { throw new RuntimeException("Cannot get connection", e); |
Connection | getConnection(String driver, String connectionString, String userName, String password) get Connection Connection con = null; try { Class.forName(driver); con = DriverManager.getConnection(connectionString, userName, password); } catch (Exception e) { e.printStackTrace(); return con; ... |
Connection | getConnection(String driver, String connectString) get Connection Connection conn = null; try { if (!_driverMap.containsKey(driver)) _driverMap.put(driver, (Driver) Class.forName(driver).newInstance()); conn = DriverManager.getConnection(connectString); } catch (SQLException ex) { System.out.println(String.format("driver: %s\nconnectString: %s", driver, connectString)); throw new RemoteException("Unable to connect to SQL database", ex); ... |