【发布时间】:2018-08-29 10:38:25
【问题描述】:
在 NetBeans 中运行我的代码以查看 mySQL 是否已连接时遇到问题。这是代码:
public static void main(String[] args) {
Connection connect = null;
try{
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/tUsers?autoReconnect=true/useSSL=TRUE","root","password");
if(connect!=null)
{
System.out.println("Connected");
}
}catch (Exception e)
{
System.out.println("RIP");
}
}
}
当我运行它时,它会打印出“RIP”。当我逐行调试它时,它从“connect = DriverManager.getConnection ...”变为“System.out.println(“RIP”),当我查看“Exception e”时,它显示“e = (java.sql.SQLNonTransientConnectionException)java.sql.SQLNonTransientConnectionException:由于基础异常而无法加载连接类:com.mysql.cj.exceptions.WrongArgumentException:数据库 URL 格式错误,无法解析 '=TRUE' 附近的连接字符串。”
现在,为什么会这样??????
【问题讨论】:
-
我建议从Connection URL Syntax开始
-
我想知道
jdbc:mysql://localhost:3306/tUsers?autoReconnect=true&useSSL=true是否会更好