Hi, I want set Required property on some column and I read that it's possible but I not found how I can make it. Can someone explain me? Thanks!
The "Required" property is readable/writable via the Column properties http://jackcess.sourceforge.net/apidocs/com/healthmarketscience/jackcess/Column.html#getProperties%28%29 (the property key is available here http://jackcess.sourceforge.net/apidocs/com/healthmarketscience/jackcess/PropertyMap.html#REQUIRED_PROP ).
I read it but I don't understand how I do write. Under there is an example, I want set required the column NAME, so after the creation of the table I set property how I think should do but... something is wrong
Table table = new TableBuilder("People") .addColumn(new ColumnBuilder("ID",DataType.LONG).setAutoNumber(true)) .addColumn(new ColumnBuilder("NAME",DataType.TEXT).setLengthInUnits(255)) .addColumn(new ColumnBuilder("SURNAME",DataType.TEXT).setLengthInUnits(255)) .toTable(database); table.getColumn("NAME").getProperties().put(PropertyMap.REQUIRED_PROP, DataType.TEXT, "");
The required property is most likely a boolean, so you probably want:
.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true);
Thanks, it work! Only a thing, after I put property, I had to do
table.getColumn("NAME").getProperties().save();
for effectively set into db the property.
Log in to post a comment.
Hi, I want set Required property on some column and I read that it's possible but I not found how I can make it. Can someone explain me? Thanks!
The "Required" property is readable/writable via the Column properties http://jackcess.sourceforge.net/apidocs/com/healthmarketscience/jackcess/Column.html#getProperties%28%29 (the property key is available here http://jackcess.sourceforge.net/apidocs/com/healthmarketscience/jackcess/PropertyMap.html#REQUIRED_PROP ).
I read it but I don't understand how I do write. Under there is an example, I want set required the column NAME, so after the creation of the table I set property how I think should do but... something is wrong
Table table = new TableBuilder("People")
.addColumn(new ColumnBuilder("ID",DataType.LONG).setAutoNumber(true))
.addColumn(new ColumnBuilder("NAME",DataType.TEXT).setLengthInUnits(255))
.addColumn(new ColumnBuilder("SURNAME",DataType.TEXT).setLengthInUnits(255))
.toTable(database); table.getColumn("NAME").getProperties().put(PropertyMap.REQUIRED_PROP, DataType.TEXT, "");
The required property is most likely a boolean, so you probably want:
.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true);
Thanks, it work! Only a thing, after I put property, I had to do
table.getColumn("NAME").getProperties().save();
for effectively set into db the property.