package com.mysqlNow;
import java.sql.Connection;
import java.sql.DriverManager;
public class exam2 {
Connection conn = null;
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("数据库驱动加载成功!!");
String url = "jdbc:mysql://localhost:3306/student?useSSL=false";
String user = "root";
String passWord = "123456";
conn = DriverManager.getConnection(url, user, passWord);
System.out.println("已成功的与MySQL数据库建立连接!!");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void main(String[] args) {
exam2 mySQL = new exam2();
mySQL.getConnection();
}
}