List of utility methods to do JDBC MySQL Connection
Connection | getConnection(String ip, String dataBaseName, String password, String username) get Connection try { Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); String urlStr = url + ip + "/" + dataBaseName + "?useUnicode=true&characterEncoding=UTF-8"; try { con = DriverManager.getConnection(urlStr, username, password); ... |
Connection | getConnection(String ip, String db, String user, String passWord) get Connection Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://" + ip + "/" + db; conn = (Connection) DriverManager.getConnection(url, user, passWord); } catch (Exception e) { e.printStackTrace(); return conn; |
Connection | getConnetion(String url, String username, String password) get Connetion final String driverName = "com.mysql.jdbc.Driver"; Connection connection = null; try { Class.forName(driverName); connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { ... |
int | getcount() getcount PreparedStatement statement = null; ResultSet rs = null; Connection conn = getConnection(); try { String sql = "SELECT count(1) from user "; statement = conn.prepareStatement(sql); rs = statement.executeQuery(); int count = 0; ... |
Connection | getDBConn() get DB Conn return DriverManager.getConnection(DBURL, USERNAME, PASSWORD);
|
Connection | getDbConnection() Gets a connection to the database. Class.forName("com.mysql.jdbc.Driver"); Connection connect = DriverManager.getConnection( "jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?" + "user=" + DB_USER + "&password=" + DB_PASSWORD); return connect; |
Connection | getDBConnection() get DB Connection Connection dbConnection = null; try { Class.forName(JDBC_DRIVER); } catch (ClassNotFoundException e) { System.out.println(e.getMessage()); try { dbConnection = DriverManager.getConnection(DB_URL, USER, PASS); ... |
Connection | getDBConnection(String database) get DB Connection Connection connection = null; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(connectionString(database)); } catch (ClassNotFoundException | SQLException ex) { ex.printStackTrace(); return connection; ... |
Connection | getDBConnection(String dbServer, String dbName, String dbUser, String dbPass) Establishes a connection to a database. Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection( "jdbc:mysql://" + dbServer + "/" + dbName + "?useUnicode=true&characterEncoding=utf-8", dbUser, dbPass); |
Connection | getDBConnection(String urlFormat, String host, Integer port, String database, String user, String password) get DB Connection String url; if (host.startsWith("jdbc:mysql://")) { url = host; } else { url = String.format(urlFormat, host, port, database); return DriverManager.getConnection(url, user, password); |