executeQuery和executeUpdate是Java中JDBC(Java Database Connectivity)接口的兩個重要方法,它們在數據庫操作中起著不同的作用。
String query = "SELECT * FROM users";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
String insertQuery = "INSERT INTO users (username, password) VALUES ('John', 'password123')";
Statement statement = connection.createStatement();
int affectedRows = statement.executeUpdate(insertQuery);
總結: