List of utility methods to do JDBC Connection Create
Connection | getConnection(String driver, String url, String user, String pass) get Connection Class<?> c = Class.forName(driver);
Driver d = (Driver) c.newInstance();
DriverManager.registerDriver(d);
return DriverManager.getConnection(url, user, pass);
|
Connection | getConnection(String driver, String url, String username, String password) get Connection Connection conn = null;
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
return conn;
|
Connection | getConnection(String driverClass, String url, String user, String password) Opens a connection to the specified database using the JDBC driver class , the url, the user name, and the password provided. Class.forName(driverClass).newInstance();
return DriverManager.getConnection(url, user, password);
|
Connection | getConnection(String driverName, String urlprefix, String host, String port, String database, String user, String password) Creates a database connection specific to the input arguments Class.forName(driverName); String url = urlprefix + host + ":" + port + "/" + database; return DriverManager.getConnection(url, user, password); |
Connection | getConnection(String drvr, String url, String nm, String pass) get Connection Class.forName(drvr);
return DriverManager.getConnection(url, nm, pass);
|
Connection | getConnection(String filename) A helper method to get the global default RDBMS connection. return getDerbyConnection(filename);
|
Connection | getConnection(String jdbcDriverName, String connectionURL) Look up an open connection. Connection conn = _openConnections.get(connectionURL); if (conn == null) { try { Class.forName(jdbcDriverName); } catch (ClassNotFoundException e) { throw new SQLException("Could not find " + jdbcDriverName + " on the classpath."); try { ... |
Connection | getConnection(String propertiesFilePath) Reads a properties file from the classpath and instantiates a java.sql.Connection with the given parameters. Properties properties = new Properties(); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFilePath); try { properties.load(is); } catch (IOException e) { throw new RuntimeException("Could not load " + propertiesFilePath + " from the classpath"); String driver = properties.getProperty("driver"); ... |
Connection | getConnection(String subprotocol, String subname, String user, String password) get Connection Connection conn = null; String conDetails = "jdbc:" + subprotocol + ":" + subname + "?user=" + user + "&password=" + password; try { conn = DriverManager.getConnection(conDetails); } catch (Exception e) { return conn; |
Connection | getConnection(String url, String username, String password) get Connection if (null == conn) { try { conn = DriverManager.getConnection(url, username, password); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); return conn; |