package com.dao;
import java.sql.Connection;

import java.sql.*;

public class BaseDao {

    /*
    *
    * @param
    * @return connection the connection of MySQL
    * @return null when get failed
     */
    public Connection getConnection(){

        String username= "root" ;
        String password = "123456";

        String driver = "com.mysql.cj.jdbc.Driver" ;
        //String url = "jdbc:mysql://127.0.0.1:3306/test";
        String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";

        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("ok");
            Connection connection = DriverManager.getConnection(url, username, password);
            return connection;
        }catch(Exception e){
            System.out.println(e);
        }
        return null ;
    }



    public static void main(String[] args) {

        Connection conn = new BaseDao().getConnection();
        if(conn != null){
            System.out.println(conn);
        }
    }


}
