Java JDBC MySQL Connection getConnection(String ip, String dataBaseName, String password, String username)

Here you can find the source of getConnection(String ip, String dataBaseName, String password, String username)

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection(String ip, String dataBaseName, String password, String username)
            throws SQLException 

Method Source Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

public class Main {
    private static String url = "jdbc:mysql://";
    private static String driver = "com.mysql.jdbc.Driver";
    private static Connection con;

    public static Connection getConnection(String ip, String dataBaseName, String password, String username)
            throws SQLException {
        try {//from  w  w w. ja v a  2  s .c  om
            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);
        } catch (SQLException e) {
            e.printStackTrace();
            throw e;
        }
        return con;
    }
}

Related

  1. getConnection()
  2. getConnection(final String host, final int port, final String schema, final String user, final String password)
  3. getConnection(String connectionType)
  4. getConnection(String dbFile)
  5. getConnection(String dbUrl, String dbName, String userName, String password)
  6. getConnection(String ip, String db, String user, String passWord)
  7. getConnetion(String url, String username, String password)
  8. getcount()
  9. getDBConn()