我正在尝试与我的数据库建立联系让我获得拒绝请帮助我
String query= "SELECT * FROM id ";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip,root,student");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while (rs.next())
{
int a=rs.getInt("rollno");
String b=rs.getString("name");
int c=rs.getInt("Maths");
int d=rs.getInt("eng");
int e=rs.getInt("ip");
model.addRow(new Object[] {a,b,c});
}
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}
答案 0 :(得分:1)
更改此行
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip,root,student");
要
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip'', root,student);
因为root是用户名而student是密码..
数据库的名称是xiiip ..
请参阅api docs ..
https://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html