[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-java
Subject:    Re: NULLs in PreparedStatement
From:       Tim Endres <time () trustice ! com>
Date:       2002-06-20 14:21:07
[Download RAW message or body]

Grigoriy,

That is my mistake. I sent that to you because I thought you were setting
fields for an update. When I realized that you were checking for NULL in
your WHERE clause, I realized that it would not work.

Sorry about that.

tim.

> Try to use the following method. 
> 
> PreparedStatement - 
> public void setNull(int parameterIndex, int sqlType) throws SQLException
> 
> - Grigoriy Puzankin
> 
> ----- Original Message ----- 
> From: "Mark Matthews" <mmatthew@thematthews.org>
> To: <dawn@amdx.net>
> Cc: <java@lists.mysql.com>
> Sent: Thursday, June 20, 2002 2:04 AM
> Subject: Re: NULLs in PreparedStatement
> 
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Dawn Lockhart wrote:
> | I have a select query that I'm composing using a PreparedStatement and
> | in some cases one of the parameters to search on is a null value. I know
> | in the MySQL command line I can just type "WHERE EmployeeID IS NULL",
> | but how do I get that into my PreparedStatment parameter?
> |
> | Sample query: SELECT * FROM Referral WHERE ID=? AND EmployeeID=? AND
> | EmployeeName=?
> |
> |            PreparedStatement stmt =
> | con.prepareStatement(retrieveByEmpQuery);
> |            stmt.setInt(1, getID(inst));
> |            stmt.setString(2, empID);
> |            stmt.setString(3, empName);
> |            ResultSet rs = stmt.executeQuery();
> |
> | The EmployeeID and EmployeeName are not required and may be null. If
> | empID or empName is set to null in my Java program, the query doesn't
> | find my record.
> |
> |
> | ---------------------------------------------------------------------
> | Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> | posting. To request this thread, e-mail java-thread3860@lists.mysql.com
> |
> | To unsubscribe, send a message to the address shown in the
> | List-Unsubscribe header of this message. If you cannot see it,
> | e-mail java-unsubscribe@lists.mysql.com instead.
> |
> 
> Right now, you have to have different PreparedStatements for each case
> where something could be null.
> 
> I don't know of any JDBC drivers that support re-writing the queries to
> have "IS NULL" when a parameter is null.
> 
> -Mark
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6-2 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAj0Q/+QACgkQlyjUJM+7nP7tWACfTxPil3p9fefnyn7kCYruALxZ
> hOsAn0JowRQ7mSMtzAEOzWg6hDXSULKX
> =jGlk
> -----END PGP SIGNATURE-----


---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail java-thread3866@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail java-unsubscribe@lists.mysql.com instead.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic