Java Utililty Methods JDBC MySQL Connection

List of utility methods to do JDBC MySQL Connection

Description

The list of methods to do JDBC MySQL Connection are organized into topic(s).

Method

ConnectiongetConnection()
get Connection
if (null == conn) {
    connect();
return conn;
ConnectiongetConnection()
get Connection
String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding);
return DriverManager.getConnection(url, loginName, password);
ConnectiongetConnection()
get Connection
if (conn == null) {
    conn = DriverManager.getConnection(url, user, password);
    return conn;
return conn;
ConnectiongetConnection()
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;
...
ConnectiongetConnection()
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();
...
ConnectiongetConnection()
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;
...
ConnectiongetConnection(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);
ConnectiongetConnection(String connectionType)
get Connection
switch (connectionType) {
case "sqlite":
    return getSqliteConnection();
case "mysql":
    return getMySQLConnection();
case "jtds":
default:
    return getJtdsConnection();
...
ConnectiongetConnection(String dbFile)
get Connection
checkConnection(dbFile);
return connections.get(dbFile);
ConnectiongetConnection(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());
...