6 messages in com.mysql.lists.javaRe: NULLs in PreparedStatement| From | Sent On | Attachments |
|---|---|---|
| Dawn Lockhart | 19 Jun 2002 14:20 | |
| Mark Matthews | 19 Jun 2002 15:03 | |
| lee | 19 Jun 2002 15:41 | |
| Altug B. Altintas | 19 Jun 2002 23:21 | |
| Grigoriy Puzankin | 20 Jun 2002 00:18 | |
| Tim Endres | 20 Jun 2002 07:20 |
| Subject: | Re: NULLs in PreparedStatement![]() |
|---|---|
| From: | Grigoriy Puzankin (grtb...@tripsoftware.com) |
| Date: | 06/20/2002 12:18:41 AM |
| List: | com.mysql.lists.java |
Try to use the following method.
PreparedStatement - public void setNull(int parameterIndex, int sqlType) throws SQLException
- Grigoriy Puzankin
----- Original Message ----- From: "Mark Matthews" <mmat...@thematthews.org> To: <da...@amdx.net> Cc: <ja...@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...@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...@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...@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...@lists.mysql.com instead.




