This code that your ResultSet rs has at least one row in it. I can see
that error popping up if there are no rows, and the line
ret=rs.getString(1);
is executed. My suggestion: when you call rs.next (); do it in an if
statement:
if (rs.next ()) {
<your current code>
}