我试图通过点击按钮执行查询,但我似乎有些不对劲。
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
try {
String host = "jdbc:mysql://localhost:3306/fabius";
String uName = "x";
String uPass = "x";
Connection con = DriverManager.getConnection(host, uName, uPass);
Statement stmt = con.createStatement();
String SQL = "SELECT * from prices";
ResultSet rs = stmt.executeQuery(SQL);
System.out.println(rs);
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
});
这会返回错误
no suitable driver found
答案 0 :(得分:0)
不知何故,这可以按要求运作。
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
try{
String host = "jdbc:mysql://localhost:3306/fabius";
String uName = "root";
String uPass = "cupcup";
Connection con = DriverManager.getConnection(host, uName, uPass);
Statement stmt = con.createStatement();
String SQL = "SELECT `HGM.L` from prices";
ResultSet rs = stmt.executeQuery(SQL);
rs.next();
System.out.println(rs.getInt(1));
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
});