Java JDBC MySQL Connection getJdbcConnection(String host, int port, String name, String user, String password)

Here you can find the source of getJdbcConnection(String host, int port, String name, String user, String password)

Description

get Jdbc Connection

License

Apache License

Declaration

public static Connection getJdbcConnection(String host, int port, String name, String user, String password) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Main {
    public static Connection getJdbcConnection(String host, int port, String name, String user, String password) {
        Connection conn = null;/*from  w  ww.  j  a  va 2  s  . co m*/
        Properties connectionProps = new Properties();
        connectionProps.put("user", user);
        connectionProps.put("password", password);

        try {
            conn = DriverManager.getConnection(
                    "jdbc:mysql://" + host + ":" + port + "/" + name
                            + "?useUnicode=yes&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull",
                    connectionProps);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return conn;
    }
}

Related

  1. getDBConnection(String dbServer, String dbName, String dbUser, String dbPass)
  2. getDBConnection(String urlFormat, String host, Integer port, String database, String user, String password)
  3. getDMPConn()
  4. getGoogleCloudDBConnection()
  5. getIonMassList()
  6. getJtdsConnection()
  7. getMaxID()
  8. getMysqlCon(String ip, String port, String dbname, String username, String password)
  9. getMysqlConnection(final String url)