Java JDBC MySQL Connection getMysqlCon(String ip, String port, String dbname, String username, String password)

Here you can find the source of getMysqlCon(String ip, String port, String dbname, String username, String password)

Description

get Mysql Con

License

Open Source License

Declaration

public static Connection getMysqlCon(String ip, String port, String dbname, String username, String password) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;

public class Main {
    public static Connection getMysqlCon(String ip, String port, String dbname, String username, String password) {
        Connection conn = null;//from   w w w.j  a  v a 2s.  c o m
        try {
            String url = "jdbc:mysql://" + ip + ":" + port + "/" + dbname;
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}

Related

  1. getGoogleCloudDBConnection()
  2. getIonMassList()
  3. getJdbcConnection(String host, int port, String name, String user, String password)
  4. getJtdsConnection()
  5. getMaxID()
  6. getMysqlConnection(final String url)
  7. getMySQLConnection(Properties props)
  8. getMySQLConnection(String cloudSqlInstance, String dbName, String userName, String password)
  9. getMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort)