“类型不匹配:无法从int转换为ResultSet”

时间:2014-03-10 17:35:01

标签: java mysql jdbc

我正在使用JCBC API连接到mySQL服务器以执行一些SQL查询(创建表,删除行等)。

但是,我在以下函数中收到“类型不匹配:无法从int转换为ResultSet”错误:

private static void deleteUnpopularArtists(Statement statement, int min_rank) throws SQLException {

    String rank = Integer.toString(min_rank);
    ResultSet resultSet = statement.executeUpdate("DELETE FROM record_artist WHERE high_chart_pos < " + rank + ";");

}

我尝试使用String.valueOf(min_rank);int rank = min_rank + "";

所以我的问题是,为什么我会收到此错误?我该怎么做才能解决它?

2 个答案:

答案 0 :(得分:4)

executeUpdate返回查询中受影响的行数。用于数据库写操作的ResultSet的概念没有意义

int rows = statement.executeUpdate
     ("DELETE FROM record_artist WHERE high_chart_pos < " + rank + ";");

答案 1 :(得分:0)

1. ExecuteUpdate returns int - for update, insert and delete operations 
where the result is expected to be int ( Number of rows affected )
2. ExecuteQuery returns resultset - useful for query statements (eg. select * from table) 
where result type is resultset (data from the table)
3. execute returns boolean - when you do not know what function to use for your 
query or for unknown dynamic sql use this function.
It returns true if result is a resultSet and false if answer is an updateCount 
or no results founds

希望这有帮助!!!