Article View: borland.public.jbuilder.database
Article #401Re: Inserting NULL values int MySQL
From: Paul Nichols [TeamB]
Date: Tue, 25 Oct 2005 17:21
Date: Tue, 25 Oct 2005 17:21
31 lines
2092 bytes
2092 bytes
Matthew wrote:
> Is it possible to insert a null value into mysql through jdbc?
>
> String test = "NULL";
> try{
> //Statement st = con.createStatement();
> stmt.executeUpdate("INSERT INTO tblStuff VALUES('10', \"" +
> test + "\")");
> }catch(SQLException e){
> System.out.println(e);
> }
>
> this is the test I have been trying to do it with. My value is passed
> into a string and then inserted into the database. When I have an empty
> string I would like to pass it a null value. Any suggestions?
John is right for Strings, but ints are not null. In your topic, you asked
about ints, but seems you are referring to Strings in the message.
Just leave String fields null, by not referencing them on inserts or updates
in your sql statements, and they should be null filled (provided, of
course, they are not required fields, or key fields). Integers, Longs,
Floats, etc. will be zero filled by default, or if you choose, you can use
a zero value to fill integer types and double types use 0.00, or 0.0.
I am not sure what MySQL version you are using. If a newer version, the
rules above should apply (I have not tried 5.0). Older versions may have
different rules. It is not a JDBC issue per se, but rather a Database
engine one.
Technical Details
Message-ID:
<435d13c8@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4277d43b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,fc452dd1c6f655e6 X-Google-Attributes: gid1073da,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <435d13c8@newsgroups.borland.com> From: "Paul Nichols [TeamB]" <paul@comp.net> Subject: Re: Inserting NULL values int MySQL Newsgroups: borland.public.jbuilder.database Date: Tue, 25 Oct 2005 12:21:43 -0500 References: <4277d43b$1@newsgroups.borland.com> Lines: 33 User-Agent: KNode/0.9.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Host: 142.131.231.207 X-Trace: newsgroups.borland.com 1130173384 142.131.231.207 (24 Oct 2005 10:03:04 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail