ackage com.anbow.jsp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class utils {
static {
try {// 加载驱动程序
***Class.forName("com.mysql.cj.jdbc.Driver");***
} catch (Exception e) {
// TODO: handle exception
}
}
// 定义一个文件扫描器 输入数据
// 定义公共的数据库属性 (url user paaword connection)
***private static String url = "jdbc:mysql://localhost:3306/teawork?serverTimezone=GMT";***
private static String user = "root";
private static String password = "root";
public static Connection connection = null;
// private ImageIcon background;
public static Connection getConnection() {
try {
connection = DriverManager.getConnection(url, user, password);
} catch (SQLException exception) {
// TODO: handle exception
exception.printStackTrace();
}
return connection;
}
public static void main(String[] args) {
Connection connection = getConnection();
if (connection != null) {
System.out.println("连接成功!");
}
}
}
Java 连接mysql 最新版本8.0以上!
猜你喜欢
转载自blog.csdn.net/amspony/article/details/102508884
今日推荐
周排行