resultSet is null

A

ashutosh

i m working in jsp and i m executing a query like :


String var="select * from reservation where starting_time='"+i+"' and
allocation_no='"+j+"'";


ResultSet rs = st1.executeQuery(var);


now i want to check whether rs contains some value in it or not.


so what syntax should i use for this...


i want to use it for if-statement like....


if (rs is null)
execute this
else
execute this


please help....
 
M

Malte

ashutosh said:
i m working in jsp and i m executing a query like :


String var="select * from reservation where starting_time='"+i+"' and
allocation_no='"+j+"'";


ResultSet rs = st1.executeQuery(var);


now i want to check whether rs contains some value in it or not.


so what syntax should i use for this...


i want to use it for if-statement like....


if (rs is null)
execute this
else
execute this


please help....

Why don't you look to the API?

stmt.executeQuery() cannot return null, so you have to look at the
ResultSet. It has a first() method, and here is a paste from javadoc:


first

public boolean first()
throws SQLException

Moves the cursor to the first row in this ResultSet object.

Returns:
true if the cursor is on a valid row; false if there are no
rows in the result set
Throws:
SQLException - if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
Since:
1.2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top