我想连接到 MySQL 数据库。在安装 MySQL 时我没有提供任何密码,所以在我的程序中我做了同样的事情,但我在连接时遇到错误。我正在使用属性文件来获取驱动程序、URL、用户名和密码。请帮助我。
这是我的代码:
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/easylibdb1","root","");
}
catch (Exception e)
{
System.out.println("Got Error While Connecting To Database...!");
e.printStackTrace();
}
这是我的属性文件内容:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.1.51:3306/easylibdb1
user=root
password=""