Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection() 

Method Source Code


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

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

public class Main {
    private static final String strUrl = "jdbc:mysql://172.21.101.175:60001/uplus?autoReconnect=true&UseUnicode=true&"
            + "characterEncoding=utf8";
    private static final String strDriver = "com.mysql.jdbc.Driver";
    private static final String strMySQLUsername = "cup_dba";
    private static final String strMySQLPassword = "123456";
    private static Connection connection;

    public static Connection getConnection() {
        try {//from  w  ww.  jav a 2s .c  o  m
            Class.forName(strDriver).newInstance();
            connection = DriverManager.getConnection(strUrl, strMySQLUsername, strMySQLPassword);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return connection;
    }
}

Related

  1. createTable(String dbFile, String tableName, String tableDefinition)
  2. deleteTableData(String tableName)
  3. getAllNames()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()