我一直在尝试在 netbeans 中练习使用 JDBC,但遇到了一个小问题,现在我加载了一个驱动程序,建立了与 SQL 的连接,但由于某种原因,我的 SQL 语句不起作用,我会很高兴任何人都可以忍受我
public void dbTest() {
try {
Class.forName(
"com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException |
IllegalAccessException |
ClassNotFoundException e) {
}
try (Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/", "root", "explore");
Statement statement = (Statement) connection.createStatement()) {
String query = "select first_name, last_name"
+ " from sakila.customer "
+ "where address_id < 10";
try (ResultSet resultset =
statement.executeQuery(query)) {
while (resultset.next()) {
String firstName =
resultset.getString("first_name");
String lastName =
resultset.getString("last_name");
System.out.println(firstName + " " + lastName);
}
}
} catch (SQLException e) {
}
}
这行代码给我带来了麻烦
Statement statement = (Statement) connection.createStatement()
谢谢!!