BrianMc1958
asked on
NEWBIE: How to return SQL boolean?
Dear Experts,
I want to use SQL just to determine the existence of a table. Normally, I return a ResultSet object. But here, it seems I should be returning a simple boolean. How do I get the response in this case? The syntax I want to use is SOMETHING liker this:
boolean bool = false;
String s = "if (exists(select * from sysobjects where name = MYTABLE))";
try
{
Statement st = conn.createStatement();
bool = st.executeQuery(s);
}
catch (SQLException e) { }
Thanks!
--BrianMc1958
I want to use SQL just to determine the existence of a table. Normally, I return a ResultSet object. But here, it seems I should be returning a simple boolean. How do I get the response in this case? The syntax I want to use is SOMETHING liker this:
boolean bool = false;
String s = "if (exists(select * from sysobjects where name = MYTABLE))";
try
{
Statement st = conn.createStatement();
bool = st.executeQuery(s);
}
catch (SQLException e) { }
Thanks!
--BrianMc1958
No, just get a boolean from the ResultSet as normal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(IOW you don't even need to get anything from the ResultSet - just see if it has results)
>> String s = "select * from sysobjects where name = MYTABLE)";
should be
String s = "select * from sysobjects where name = MYTABLE";
of course. Better not * if possible - just one column
should be
String s = "select * from sysobjects where name = MYTABLE";
of course. Better not * if possible - just one column
ASKER
I've tried it. I'm getting good results. Thanks!
--BrianMc1958
--BrianMc1958
No problem
i think the SQL should be:
select name from sysobjects where name='MYTABLE'.
sometime you want to avoid select * because not all columns can be retrieved by normal user.
select name from sysobjects where name='MYTABLE'.
sometime you want to avoid select * because not all columns can be retrieved by normal user.
>> i think the SQL should be ...
Only if it's a char type. There's no indication of that in the original
Only if it's a char type. There's no indication of that in the original
i think name in sysobjects is char type :)
There's also no indication of what 'sysobjects' is ;-)
sysobjects normally is a system table in Sybase, which holds information of, well, system objects :) , including tables
ASKER
Yikes! I forgot to award points! Thanks again, everybody!
--BrianMc1958
--BrianMc1958
:-)
To be generic, you can use:
select 1 [from xxx] where <boolean expression>
to return boolean expression in SQL.
select 1 [from xxx] where <boolean expression>
to return boolean expression in SQL.