JDBC链接MySQL数据库

package 选课管理系统;

import java.sql.*;
public class 连接数据库 {
    static Connection con = null;
    static String datascore = "教务系统";
    static String URL = "jdbc:mysql://localhost:3306/"+datascore+"?useUnicode=true&characterEncoding=utf-8&useSSL=false"; 
    static String USER = "root"; 
    static String PASSWORD = "root";
    static {
        try{ 
            Class.forName("com.mysql.jdbc.Driver");
           }catch(ClassNotFoundException e) {
                 System.out.print(e);
           }
           
        try{ 
            con=DriverManager.getConnection(URL,USER,PASSWORD);
          }catch(SQLException e) {
              System.out.println(e);
          }
        
    }
    public static Connection GetConnection()
    {
        return con;
    }
}

 

posted @ 2018-07-03 16:36  TTTCoder  阅读(174)  评论(0编辑  收藏  举报