Hi,
I use ResultSet to insert record to a table.
The table has several fields with default value.
When I do insert, I do not fill value for those default values.
I expect the inserted record will have value from the default values,
but it's not, still NULL.
Is this bugs?
I read from JDBC tutorial about insert record using moveToInsertRow it
said something like this:
"You might also wonder what happens if you insert a row without
supplying a value for every column in the row. If a column has a
default value or accepts SQL NULL values, you can get by with not
supplying a value. If a column does not have a default value, you will
get an SQLException if you fail to set a value for it. You will also
get an SQLException if a required table column is missing in your
ResultSet object."
Isn't it means if default value even the field is not filled, it
should use the default value?


Example:
Table Customer
Fields:
- CustomerId INT AUTO_INCREMENT PRIMARY KEY
- CustomerCode VARCHAR
- CustomerName VARCHAR
- LastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Connection conn;
String SQL = "SELECT * FROM Customer";
PreparedStatement ps = conn.prepareStatement(SQL,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = ps.executeQuery();
rs.moveToInsertRow();
rs.updateString("CustomerCode", "001");
rs.updateString("CustomerName", "AAA");
rs.insertRow();
rs.close();

The result:
CustomerId = 1 (auto filled)
CustomerCode = 001
CustomerName = AAA
LastModified = NULL (I expect it to fill the default value, the
current timestamp)

If it is default behaviour of H2, is there a way to change this
behaviour, using system property or anything?

Thanks

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to