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()
ありがとう!!