AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

prepared statement : finding records with null values in whe

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Ian deSouza
Guest





PostPosted: Thu Apr 01, 2004 4:43 pm    Post subject: prepared statement : finding records with null values in whe Reply with quote



OK,

After reviewing some articles, it appears that we can't use

"select * from mytable where mycol = ?"

when we >>might<< have a null value for mycol and we have to use a
variant of the sql "mycol is null" when the value were setting is
null.

The problem I'm having is that for my many table, each may have many
columns in the where clause, where any column can be null (can you see
the permutations growing)..

Any ideas on how to do this with PreparedStatement generically
(database neutral).

Thanks in advance, Ian
Back to top
Andree Große
Guest





PostPosted: Fri Apr 02, 2004 8:35 am    Post subject: Re: prepared statement : finding records with null values in Reply with quote



Ian deSouza wrote:

Quote:
OK,

After reviewing some articles, it appears that we can't use

"select * from mytable where mycol = ?"

when we >>might<< have a null value for mycol and we have to use a
variant of the sql "mycol is null" when the value were setting is
null.

The problem I'm having is that for my many table, each may have many
columns in the where clause, where any column can be null (can you see
the permutations growing)..

Any ideas on how to do this with PreparedStatement generically
(database neutral).

where (field1 like '%something%' or filed1 is null)
and (field2 like '%another thing%' or filed2 is null)
and ...
or ...

HTH A.G.

Back to top
Robert Klemme
Guest





PostPosted: Fri Apr 02, 2004 8:56 am    Post subject: Re: prepared statement : finding records with null values in Reply with quote




"Andree Große" <user (AT) example (DOT) net> schrieb im Newsbeitrag
news:c4j8ku$o93$1 (AT) ppd00021 (DOT) deutschepost.de...
Quote:
Ian deSouza wrote:

OK,

After reviewing some articles, it appears that we can't use

"select * from mytable where mycol = ?"

when we >>might<< have a null value for mycol and we have to use a
variant of the sql "mycol is null" when the value were setting is
null.

The problem I'm having is that for my many table, each may have many
columns in the where clause, where any column can be null (can you see
the permutations growing)..

Any ideas on how to do this with PreparedStatement generically
(database neutral).

where (field1 like '%something%' or filed1 is null)
and (field2 like '%another thing%' or filed2 is null)
and ...
or ...

HTH A.G.

I don't think that's what the OP wanted. The only idea I have looks quite
ugly:

"select * from mytable where ( ( 1 = ? and mycol = ? ) or ( 0 = ? and
mycol is null ) ) and ..."

Continue for other columns as well. Use 1 for parameter 1 and 3 if you
want to provide a value, use 0 if you want to check for NULL etc. I
didn't test it but it might work. Of course this increases the number of
prepared statement parameters by a factor 3 but that might still be better
than permutations...

Wait, there's another option: use a function like ISNULL:

"select * from mytable where ISNULL(mycol, 'a_value_you_dont_expect') = ?
and ...."

Then map null to 'a_value_you_dont_expect'. Downside is, that this is
type and db dependend, i.e., you have to map numerical values to something
different from varchar values.

Regards

robert


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.