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);
总结: