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!

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

if rs:
    rs.moveFirst()

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()

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.