ResultSet已关闭.为什么?

Bul*_*lit 0 java sqlite resultset

我有一个小问题.我启动我的应用程序,并在启动查询并比较后rs == null得到错误ResultSet is closed.

这是代码:

error_code = NO_ERROR;
    try
    {
        ArrayList <Harmonogram> al = new ArrayList <Harmonogram> ();
        ResultSet rs = stat.executeQuery(myQuery);
        if (rs == null)
        {
            return null;
        }else{
            Harmonogram harm = new Harmonogram(rs.getLong(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getLong(5), rs.getString(6));
Run Code Online (Sandbox Code Playgroud)

在此之后我得SQLException告诉我:ResultSet is closed.

Ale*_*yak 7

您使用不正确的方法检查是否ResultSet有任何数据.

代替

if ( rs == null )
{
    return null;
}
Run Code Online (Sandbox Code Playgroud)

使用

if ( ! rs.next( ) )
{
    return null;
}
Run Code Online (Sandbox Code Playgroud)