> On 31. jan. 2015, at 20.22, Bob M <[email protected]> wrote:
> 
> Hi Dyre
> 
> I am still not grasping this.................
> 
> I have
> psInsert = conn.prepareStatement("INSERT INTO TABLE VALUES(?, ?......, ?)
> [27 of them]
> psInsert.setString(1, date);
> ................
> psInsert.setString(25, class);
> psInsert.setString(26, Trade_ID);
> 
> but I am unclear what to put for the final line referring to Profit and
> where I wish to set it to NULL initially which is the default

There are two different strategies here:

1) Just insert an SQL NULL manually:

psinsert.setNull(<number>, java.sql.Types.DOUBLE); // See javadoc for 
PreparedStatement

or, psinsert.setNull(“PROFIT_LOSS”, java.sql.Types.DOUBLE)

2) Change the definition of the table:

CREATE TABLE T(….., PROFIT_LOSS DOUBLE DEFAULT NULL, …)

then when inserting

INSERT INTO T(<col1>, <col2>, …, <col after PROFIT_LOSS>, <more columns>,…) 
VALUES (?,?,… ?)

You have to spell out the columns you are inserting into, unless the columns 
with default values are the last columns in the table. In that case you can 
just omit them in the insert

> 
> Bob M
> 
> 
> 
> --
> View this message in context: 
> http://apache-database.10148.n7.nabble.com/Initializing-a-new-record-where-field-is-NULL-by-default-tp143732p143735.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.

Reply via email to