Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using sql first() function

843859Aug 27 2007 — edited Nov 20 2014
Consider following code
        Calendar calendar     = Calendar.getInstance();
        int currentFiscalYear = calendar.get( Calendar.YEAR );

        query = "SELECT FIRST( amount_allocated ) FROM budget     WHERE department_id = '" +
                 departmentId + "' AND fiscal_year = " + currentFiscalYear;
        
        resultSet = statement.executeQuery( query );

        if( resultSet.next() )
        {            
            return true;
        }
        else
        {
            return false;
        }
I execute this code on a table with folowing columns.

department_id, head_id, fiscal_year, amount_alloc, amount_remain

when I execute this code, on such records that none of them fullfills the

select condition, the resultSet.next() method still works and does not

return false, it still returns ture. But if I call result.wasNull() inside the if

block, after calling a getter method. the wasNull() returns true. Why the

resultSet returns ture even if no record is exists in the table for the

current year. Please guide.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2007
Added on Aug 27 2007
6 comments
121 views