<分区>
我正在尝试使用下面的代码连接到 MySQL 数据库,但我的尝试失败了。
这是我的尝试:
private static Connection conn = null;
private static String url = "jdbc:mysql://localhost/";
private static String dbName = "proj1";
private static String driver = "com.mysql.jdbc.Driver";
private static String userName = "root";
private static String password = "root";
public static int setupConnection ()
{
try{
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,"root","root");
return 1;
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
return 0;
}
}
安装MySQL时,我记得输入密码“root”,但我不能100%确定用户名是否自动分配为“root”。
我收到错误消息:com.mysql.jdbc.Driver