Preface: It is an honor to encounter a small problem today about Jfinal's Getint (), Getlong () method and MySQL data type Association. If the type of int field in the MySQL database uses unsigned, then jfinal will use Getlong (), and if the Int type field is not unsigned, then jfinal () is used, otherwise the type mismatch error occurs.
Understanding the MySQL data typeFirst, let's look at the MySQL data type, here we only see the type of int
Int[(m)] |
Signed values: 2147683648 to 2147683647 (-231 to 231-1) Unsigned values: 0 to 4294967295 (0 to 232-1) 4 bytes |
This means that if your data field is such a child,
' UID ' int (one) not NULL DEFAULT ' 0 ' COMMENT ' user ID '
Then m=11 is correct, because the "-" (negative number) is considered to be the maximum length of 11 bits.
And if your data field is like this,
' UID ' int (one) unsigned not NULL COMMENT ' user ID '
Then m=11 is meaningless, because the maximum length is 10 bits, if you are more professional, at this time, your data field should be like this
' UID ' int (ten) unsigned not NULL COMMENT ' user ID '
If you want to learn more about MySQL Data Insider, please check out the http://www.cnblogs.com/kwishly/archive/2012/04/19/2457450.html article.
Understanding jfinal Data TypesAgain, here we only focus on the Getlong () and Getint () methods.
/** * Get attribute of MySQL type:int, Integer, tinyint (n) n > 1, smallint, mediumint */public integer GETINT (String attr) { return (Integer) attrs.get (attr);}/** * Get attribute of MySQL type:bigint, unsign int */public Long Getl Ong (String attr) { return (Long) attrs.get (attr);}
Note the difference between unsigned int and int。
int data for Java
System.out.println ("2147683647"); System.out.println ("4294967295"); System.out.println (integer.max_value);//2147483647
So you can see why jfinal was designed that way.
Summary: small knowledge, long insight.
How to use mysql:jfinal data