Paul
unread,Oct 13, 2011, 5:43:13 AM10/13/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to H2 Database
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