Java JDBC MySQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
// LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,

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

public class Main {
    private final static String jdbc = "com.mysql.jdbc.Driver";
    private final static String sqlHome = "jdbc:mysql://localhost:3306/test";
    private final static String other = "?useUnicode=true&characterEncoding=utf-8";
    private final static String userName = "root";
    private final static String passWord = "zzHe";

    public static Connection getConnection() {
        Connection con = null;// w  w w .j  a  va2s.  c  om
        try {
            Class.forName(jdbc);

            con = DriverManager.getConnection(sqlHome + other, userName, passWord);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }
}

Related

  1. getConnection()
  2. getConnection()
  3. getConnection()
  4. getConnection()
  5. getConnection()
  6. getConnection()
  7. getConnection()
  8. getConnection()
  9. getConnection()