当前位置: 技术问答>java相关
简单的sql问题
来源: 互联网 发布时间:2015-09-05
本文导语: 如下所示,如果查询结果不存在的时候,不知道应该怎么判断,可以用myResults==null 吗?在程序中通不过,请指教。 ResultSet myResults = myStatement.executeQuery("SELECT frequency FROM yuliao WHERE keyword='上海'"); |...
如下所示,如果查询结果不存在的时候,不知道应该怎么判断,可以用myResults==null 吗?在程序中通不过,请指教。
ResultSet myResults = myStatement.executeQuery("SELECT frequency FROM yuliao WHERE keyword='上海'");
ResultSet myResults = myStatement.executeQuery("SELECT frequency FROM yuliao WHERE keyword='上海'");
|
用这个:if(myResults.next())
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
最开始游标相当于在第0条记录。
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
最开始游标相当于在第0条记录。
|
while(resultset.next()){
yourcode;
}
yourcode;
}