Java JDBC MySQL Connection getMySQLConnection(String hostName, String dbName, String userName, String password)

Here you can find the source of getMySQLConnection(String hostName, String dbName, String userName, String password)

Description

get My SQL Connection

License

Open Source License

Declaration

public static Connection getMySQLConnection(String hostName, String dbName, String userName, String password)
            throws SQLException, ClassNotFoundException 

Method Source Code


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

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

public class Main {
    public static Connection getMySQLConnection() throws SQLException, ClassNotFoundException {
        String hostName = "localhost";
        String dbName = "test1";
        String userName = "root";
        String password = "123456";

        return getMySQLConnection(hostName, dbName, userName, password);
    }//w  w w .  j a  v a2s .co  m

    public static Connection getMySQLConnection(String hostName, String dbName, String userName, String password)
            throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");

        String connectionURL = "jdbc:mysql://localhost:3306/test1";

        Connection conn = DriverManager.getConnection(connectionURL, userName, password);
        return conn;
    }
}

Related

  1. getMysqlCon(String ip, String port, String dbname, String username, String password)
  2. getMysqlConnection(final String url)
  3. getMySQLConnection(Properties props)
  4. getMySQLConnection(String cloudSqlInstance, String dbName, String userName, String password)
  5. getMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort)
  6. getMysqlIndices(String conString)
  7. getNewDatabaseConnection(String dbUser, String dbPassword)
  8. getRssminerDB()
  9. getSearchReaderConnection()