【发布时间】:2016-06-27 09:47:32
【问题描述】:
错误是“异常:无效的数据库地址:jdbc:mysql://localhost:3306/library?user=root&password=myPassword” 我正在使用 MySQL 数据库并且是这方面的初学者,所以我有点困惑。我在 MySQL 中的数据库名称是“library”....所以有人能指出我正确的方向吗?
import java.sql.*;
public class connectToMySQL {
public static void main(String[] args) {
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/library?user=root&password=myPassword");
System.out.println("Connected with the database!");
}
catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
【问题讨论】:
-
您需要注册您的数据库驱动程序。类似
Class.forName("com.mysql.jdbc.Driver"); -
@user1875195 自 2007 年以来没有。