MySQL field type
CREATE TABLE IF NOT EXISTS `user` (
`USER_ID` bigint(20) NOT NULL auto_increment,
`USER_ABOUT_YOU` varchar(255) default NULL,
`USER_COMMUNITY` tinyblob,
`USER_COUNTRY` varchar(255) default NULL,
`USER_GENDER` varchar(255) default NULL,
`USER_MAILING_LIST` bit(1) default NULL,
`USER_NAME` varchar(255) default NULL,
`USER_PASSWORD` varchar(255) default NULL,
PRIMA开发者_如何转开发RY KEY (`USER_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Why is the USER_COMMUNITY defined as tiny blob. This field accepts a value of checkbox. When i change it to some other datatype i get an error? Why is to so?
http://www.vaannila.com/spring/spring-hibernate-integration-1.html
That's how it is defined:
@Column(name="USER_COMMUNITY")
public String[] getCommunity() {
return community;
}
public void setCommunity(String[] community) {
this.community = community;
}
The table doesn't store the checks but an array of Strings. And it looks like, TINYBLOB
is the correct datatype on MYSQL for storing arrays.
There is no 'value of checkbox'. A checkbox returns a string as do most other HTML input controls. These checkboxes actually return a list of values, because they all have the same name. I don't know how this value is stored actually, but I can imagine that is is stored as an array of string with some accompanieing meta data. This kind of data will be hard to store in another field type.
In what field type did you want to change it, and what was the error you got?
I would actually not store this data this way, but give user
a detail table instead in which you can store the communities the user is a member of. But this tutorial seems to focus more on jsp than database normalisation. ;)
精彩评论