0

Hello I am quite new programming in Jython,

I am working with DB. I a send SQL Statements, but I want to handle the zero rows in Resulset.

rs = dataSource.performQuery(sqlstatement)
rs.moveFirst()

I dont know which condition has to be set when the Resulset doesnt has any row. When I say rs.moveFirst() it sends me an error because there is no rows.I tried many things like:

rs = dataSource.performQuery(sqlstatement)
rs.moveFirst()
while rs.moveNext: --------->This part doesnt work,it enters even there is any row in the rs
result=rs.getrow()
for rows in result:
arr=str(rows.atrr_value)
try:
rs.moveNext()
except:
print"End of loop"

I dont know what else to do in order to break the loop if the rs has no row. What could be a solution?

Thank you for your help!

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by bvdet
0

The object assigned to rs should evaluate False if empty. Have you tried:

if rs:
    rs.moveFirst()
0

Hi,

Yes, I have tried all this things:

if rs.moveNext() !=None:
if rs is not None:
if rs:
if rs.moveNext():

And anything work. When I run it, it says that always have rows when is not true.

Any idea?

Thanks for your help

The object assigned to rs should evaluate False if empty. Have you tried:

if rs:
    rs.moveFirst()
0

In that case, you can use a try/except block to catch the error.

try:
    rs.moveFirst()
    # other code as needed
except Exception, e: # substitute the actual exception raised
    # do whatever
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.