为什么要启动mysql workbech,java才能连接mysql数据库呢
情况是这样的:刚开机了,右下角的MYSQL图标是启动状态,但运行时,if(conn != null) 语句没有反应的,即不打印OK,也不打印NO
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/guo?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false";
String username = "root";
String password = "123456";
Connection conn = DriverManager.getConnection(url, username, password);
if(conn != null) {
out.println("OK");
}else {
out.println("NO");
}
}catch (SQLException e){
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
情况是这样的:刚开机了,右下角的MYSQL图标是启动状态,但运行时,if(conn != null) 语句没有反应的,即不打印OK,也不打印NO
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/guo?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false";
String username = "root";
String password = "123456";
Connection conn = DriverManager.getConnection(url, username, password);
if(conn != null) {
out.println("OK");
}else {
out.println("NO");
}
}catch (SQLException e){
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}