MySQL Forums
Forum List  »  Stored Procedures

How to return null/empty resultset from SP??
Posted by: Ming Yeung
Date: December 11, 2005 08:50AM

Hi guys,

I tried to search for my problem, but with no luck.
Below is my SP, it is a very simple one.

CREATE PROCEDURE `adminCheckLogin`(IN inUsername varchar(20), IN inPassword char(32))
BEGIN
DECLARE ret_id INT;
SELECT id INTO ret_id FROM admin WHERE username = inUsername AND password = inPassword;

IF ret_id IS NOT NULL THEN
UPDATE admin SET date_lastlogin = NOW() WHERE id = ret_id;
END IF;

SELECT ret_id;
END

What It does is to check the user's login and if the user is there, then update the login time, and return the user id.

If the user is found, of course, it returns the user id. But the problem I have is that the SP returns(always) 0 if user is not found, which it shouldn't.

Therefore, the first statement from the java code will always pass:
if(rs.next())
// Found...
else
// Not found ...

...
So how do I return a null resultset ?? e.g. SELECT NULL, etc..;

Thanks a lot.

Options: ReplyQuote


Subject
Views
Written By
Posted
How to return null/empty resultset from SP??
5188
December 11, 2005 08:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.