package practice.main;
import java.sql.Connection;
import java.sql.DriverManager;
public class Day22main {
public static void main(String[] args) {
String driverName = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/gao2"; // gao2为你的数据库
String userName = "root"; // 你的用户名(安装mysql时的设置的)
String userPwd = "***********"; // 你的密码
try {
Class.forName(driverName);
System.out.println("加载驱动成功!");
} catch (Exception e) {
//想知道哪个时数据库只需要
System.out.println("加载驱动失败!");
}
try {
//
Connection dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("连接数据库成功!");
} catch (Exception e) {
System.out.print("mysql连接失败!");
}
}
}
|