List of utility methods to do JDBC MySQL Connection
Connection | getConnection() get Connection if (null == conn) { connect(); return conn; |
Connection | getConnection() get Connection String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding); return DriverManager.getConnection(url, loginName, password); |
Connection | getConnection() get Connection if (conn == null) { conn = DriverManager.getConnection(url, user, password); return conn; return conn; |
Connection | getConnection() get Connection Connection conn = conns.get(); if (conn == null) { Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/insurancemall"; conn = DriverManager.getConnection(url, "root", ""); conns.set(conn); return conn; ... |
Connection | getConnection() get Connection Connection conn = session.get(); if (conn == null) { try { conn = DriverManager.getConnection(url, user, password); conn.setAutoCommit(false); session.set(conn); } catch (SQLException e) { e.printStackTrace(); ... |
Connection | getConnection() get Connection try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("Connecting to database..."); connection = (Connection) DriverManager.getConnection(DB_URL, USER, PASS); } catch (Exception e) { System.out.println("Class path not found"); return connection; ... |
Connection | getConnection(final String host, final int port, final String schema, final String user, final String password) get Connection Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + schema, user, password); |
Connection | getConnection(String connectionType) get Connection switch (connectionType) { case "sqlite": return getSqliteConnection(); case "mysql": return getMySQLConnection(); case "jtds": default: return getJtdsConnection(); ... |
Connection | getConnection(String dbFile) get Connection checkConnection(dbFile);
return connections.get(dbFile);
|
Connection | getConnection(String dbUrl, String dbName, String userName, String password) create a DB connection to mysql if (conn == null) { try { String connString = "jdbc:mysql://" + dbUrl + ":" + port + "/" + dbName + "?autoReconnect=true"; conn = DriverManager.getConnection(connString, userName, password); } catch (SQLException ex) { System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); ... |