Forums Register Login

What would be returned when the record is empty?

+Pie Number of slices to send: Send
Dear All,

I need to check whether a record has been created. If not, I will create it using JDBC. I was wondering what would the ResultSet contain if no record is returned? Would it be null? or something else? I would have tested it however I don't have a compiler handy at this moment

Currently, i am doing it using count(*) to see it return 0 or not.

Thanks for your help.
+Pie Number of slices to send: Send
If you are using count(*) you know that your ResultSet will always contain 1 record. If you do a "Select * from whatever" and the table is empty, so is your ResultSet.
+Pie Number of slices to send: Send
Thanks Paul

so the answer is an emoty resultset instead of null?
+Pie Number of slices to send: Send
Chit,
Queries never return null resultsets. So yes, you would get an empty resultset back.

That said, I prefer the select count(*) approach. It better expresses your intent by showing you are only using the count, not the data. It can also be faster depending on your indexes and schema.
+Pie Number of slices to send: Send
Chit Ming, When ever a select query doesn't return any rows
rs.next() returns false when you call it for the first time itself.
+Pie Number of slices to send: Send
Right. Noting that the 0 returned by select count(*) is a row with a value.
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 837 times.
Similar Threads
Using a MIDlet to navigate a database recordset
Locking idea for URLYBird
Urlybird 1.1.1 record design
B&S locking issues & findByCriteria
Update or Insert
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:56:09.