我有一个让我发疯的问题,我真的不习惯使用 mySQL 数据库,我真的需要一些帮助。我想连接到我的 MySQL 数据库以运行查询并最终能够将数据加载到数据库中并测量加载、查询等所消耗的时间,因此我可以比较不同类型数据库的性能。我认为我让 forName 工作,但现在它抱怨 dbUrl。有人可以向我解释我做错了什么吗?
提前致谢!
import java.sql.*;
import java.util.Properties;
import javax.sql.*;
public class jdbcdemo{
public static void main(String args[]){
String dbtime;
String dbUrl = "jdbc:mysql://localhost:3306/Meeting";
String dbClass = "com.mysql.jdbc.Driver";
String query = "Select * FROM customer";
Properties properties = new Properties();
properties.put("user", "student");
properties.put("password", "ingan86");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection (dbUrl,properties);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
dbtime = rs.getString(1);
System.out.println(dbtime);
}
con.close();
}
catch(SQLException e) {
e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
堆栈跟踪:
java.sql.SQLException: Access denied for user 'student'@'localhost' (using password: YES)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:798)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3700)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1203)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at jdbcdemo.main(jdbcdemo.java:22)