mysql常见问题处理
The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized or represents more than one time zone.
转载: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized or represents more than one time zone.
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure问题解决
转载: Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure问题解决
MySQL8.0连接url
转载: MySQL8.0连接url
数据库连接测试用例(代码)
@Test
public void run() throws ClassNotFoundException, SQLException {
//1,加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2、用户信息和URL
String url = "jdbc:mysql://localhost:3306/uedu?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
String username = "root";
String password = "123456";
//3、连接成功,数据库对象 Connection代表数据库
Connection connection = DriverManager.getConnection(url, username, password);
//4、执行SQL对象 statement 执行sql对象
Statement statement = connection.createStatement();
//5、执行SQL对象 去 执行SQL,可能存在结果,查看返回结果
String sql = "SELECT * FROM user";
ResultSet resultSet = statement.executeQuery(sql);//返回结果集,结果封装了我们全部查询的结果
while (resultSet.next()) {
System.out.println("彭于晏,你的mysql连接成功.......");
}
//6、释放连接
resultSet.close();
statement.close();
connection.close();
}