B4J Question ExecQueryAsync returns closed resultset

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

I am using the following:

B4X:
sSQL = "some sql query"
Dim SenderFilter As Object = pConn.ExecQueryAsync("SQL", sSQL, Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
if Not(rs.NextRow) Then
    ' do something else
else
    ' do this code
end if
rs.close

I have found the if no rows are returned from the query the resultset appears to be closed on return, so the 'if Not(rs.NextRow) Then' failes with an error, com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.

Is this normal ?

Regards

John.
 

DonManfred

Expert
Licensed User
Longtime User
If there are no results the Resultset is not Initialized.
B4X:
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
if rs.isInitialized then
    if Not(rs.NextRow) Then
        ' do something else
    else
        ' do this code
    end if
    rs.close
else
    ' Do something else as the query returns 0 Results.
end if
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I get the same error when checking if the resultset is initialized
That sounds strange, assuming you are using the same code as DonManfred. Isinitialised is a B4J function that merely checks whether the wrapped ResultSet object is null or not. I wouldn't expect it to be capable of returning a SQLServerException as it doesn't touch the object itself.

Java:
  public boolean IsInitialized() {
    return (this.object != null);
  }
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
That sounds strange, assuming you are using the same code as DonManfred. Isinitialised is a B4J function that merely checks whether the wrapped ResultSet object is null or not. I wouldn't expect it to be capable of returning a SQLServerException as it doesn't touch the object itself.

Java:
  public boolean IsInitialized() {
    return (this.object != null);
  }
Yep, strange indeed. I dont know why the rs is return as closed. It is initialised, as I have checked that. It is the rs.nextrow that cause's the exception.
 
Upvote 0
Top