This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

MySQL Prepared Statement & NULL  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an app with a CachedRowSetImpl that reads from a MySQL database (using "com.mysql.jdbc.Driver")

I'm passing the RowSet a prepared statement that looks like this:



...and then setting the parameter with setString, setInt, etc... I'm using the LIKE operater to allow me to enter the '%' wildcard into the parameter.

The only place where its falling down is when I try to select NULL fields. Using setNULL does not work as MySQL treats NULL differently from other databases. The usual way to execute a clause on NULL is



...but using the 'LIKE' or '=' operators fails when used with NULL under MySQL.

So is there any way I can put a WHERE clause on a column with a NULL value using a PreparedStatement like I have above?
 
author & internet detective
Posts: 39054
714
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob J Ford wrote:...but using the 'LIKE' or '=' operators fails when used with NULL under MySQL.

So is there any way I can put a WHERE clause on a column with a NULL value using a PreparedStatement like I have above?


It should fail. Testing for equality (or like) is undefined according to the SQL starndard. MySql is behaving correctly. You have to use "is null" to check for null in SQL.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!