import com.mysql.jdbc.Driver;

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

//链接数据库
public class ConnDB {
    //获取数据库的链接
    public static Connection getConn(){
           Connection conn=null;
           //加载驱动类
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/vote","root","123456");

        }catch (Exception e){
            System.out.println("数据库链接失败");
        }
           return conn;
    }

  //关闭数据库链接
    public static void closeConn(Connection conn){
        try{
            if(conn!=null){
                conn.close();
            }
        }catch (Exception e){
            System.out.println("数据库关闭失败");
        }
    }

    public static void main(String[] args) {
        getConn();
    }



}
