帮客户做网站的公司,武穴建设网站,海口网约车从业资格证,网站建设的书 推荐前言
这里主要是 由于之前的一个 datetime 存储的时间 导致的问题的衍生出来的探究
探究的主要内容为 int 类类型的存储, 浮点类类型的存储, char 类类型的存储, blob 类类型的存储, enum/json/set/bit 类类型的存储
本文主要 的相关内容是 int 类类型的相关数据的存储 …前言
这里主要是 由于之前的一个 datetime 存储的时间 导致的问题的衍生出来的探究
探究的主要内容为 int 类类型的存储, 浮点类类型的存储, char 类类型的存储, blob 类类型的存储, enum/json/set/bit 类类型的存储
本文主要 的相关内容是 int 类类型的相关数据的存储
这部分数据 客户端 和 服务器这边的交互 主要是以字符串的形式交互
服务器这边的存储 主要是 单字节存储, 双字节存储, 三字节存储, 四字节存储, 八字节存储 mysql类型 和 java类型对应
驱动的 ResultSetImpl 获取数据的时候有一层封装
因此不管是 tinyint, smallint, medinumint, int 在业务代码上面获取到的都是 Integer 接收
unsigned_int 因为 java 中 int 已经覆盖不了值域, 因此使用了 long 来接受
bigint 对应于类型 long 接收
unsigned_bigint 和上面 unsigned_int 同理, 使用了 BigInteger 接收
decimal, unsigned_bigdecimal 使用了 BigDecimal 接收
float, double 使用 Float, Double 接收 mysql 中 tinyint 的服务器客户端的数据交互
创建表 以及插入测试数据
CREATE TABLE tz_test (id int(11) NOT NULL AUTO_INCREMENT,field1 tinyint(4) DEFAULT NULL,PRIMARY KEY (id)
) ENGINEInnoDB AUTO_INCREMENT2 DEFAULT CHARSETutf8INSERT INTO test.tz_test(id, field1) VALUES (1, 122); 测试脚本如下
package com.hx.test07;/*** Test06MysqlTimezone** author Jerry.X.He* version 1.0* date 2023/4/24 16:26*/
public class Test06MysqlTimezone {// Test06MysqlTimezonepublic static void main(String[] args) {String url jdbc:mysql://10.60.50.16:3306/test?useUnicodetruecharacterEncodingUTF-8autoReconnecttrueautoReconnectForPoolstrueuseSSLfalse;String username root;String password root;JdbcTemplate jdbcTemplate Test14GenExpertSql.getMysqlJdbcTemplate(url, username, password);String sql select * from tz_test; ;ListMapString, Object list jdbcTemplate.queryForList(sql);int x 0;}} mysql 是将给定的 tiny int 的数据以 字符串的形式 交互给客户端的
mysql 服务器中对应的类型为 TINY 与客户端的交互, 将给定的 tinyint 转换为 十进制 的字符串表示, 然后 响应回去
因为是数字在大多数的编码中都是相同的, 所以这里 my_charset_numeric 直接在 mysql 中定义的是 my_charset_latin1 mysql服务器 中 tinyint 的数据存储
以单字节存储, 可以分为 无符号 和 有符号
这里可以看出, 如果你设置的数字超出了 单字节 可以表示的数据的值域, mysql 会将值调整为边界, 比如如下 语句, 会将 field1 更新为 127
update tz_zone set field1 399 where id 1; mysql 中 smallint 的服务器客户端的数据交互
和上面 tinyint 相同
mysql 服务器中对应的类型为 SHORT 与客户端的交互 的转换 和 tinyint 的处理类似 mysql 服务器 smallyint 的存储
以双字节存储, 可以分为 无符号 和 有符号
这里可以看出, 如果你设置的数字超出了 单字节 可以表示的数据的值域, mysql 会将值调整为边界, 比如如下 语句, 会将 field1 更新为 32767
update tz_zone set field1 399999999 where id 1; mysql 中 mediumint 的服务器客户端的数据交互
和上面 tinyint 相同
mysql 服务器中对应的类型为 INT24 与客户端的交互 的转换 和 tinyint 的处理类似 mysql 服务器 mediumint 的存储
以三字节存储, 可以分为 无符号 和 有符号
这里可以看出, 如果你设置的数字超出了 单字节 可以表示的数据的值域, mysql 会将值调整为边界, 比如如下 语句, 会将 field1 更新为 8388607
update tz_zone set field1 399999999 where id 1; mysql 中 int 的服务器客户端的数据交互
和上面 tinyint 相同
mysql 服务器中对应的类型为 LONG 与客户端的交互 的转换 和 tinyint 的处理类似 mysql 服务器 int 的存储
以四字节存储, 可以分为 无符号 和 有符号
这里可以看出, 如果你设置的数字超出了 单字节 可以表示的数据的值域, mysql 会将值调整为边界, 比如如下 语句, 会将 field1 更新为 2147483647
update tz_zone set field1 39999999999999 where id 1; mysql 中 bigint 的服务器客户端的数据交互 和上面 tinyint 相同
mysql 服务器中对应的类型为 LONGLONG 与客户端的交互 的转换 和上面同理, 获取到 longlong, 然后再基于 longlong10_to_str 转换为 字符串表示 mysql 服务器 bigint 的存储
将传入的 longlong 转换为 longlong, 然后以八字节存储 完 文章转载自: http://www.morning.rlksq.cn.gov.cn.rlksq.cn http://www.morning.yzfrh.cn.gov.cn.yzfrh.cn http://www.morning.fygbq.cn.gov.cn.fygbq.cn http://www.morning.chhhq.cn.gov.cn.chhhq.cn http://www.morning.krbjb.cn.gov.cn.krbjb.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.ttxnj.cn.gov.cn.ttxnj.cn http://www.morning.pmnn.cn.gov.cn.pmnn.cn http://www.morning.prmbn.cn.gov.cn.prmbn.cn http://www.morning.qlpyn.cn.gov.cn.qlpyn.cn http://www.morning.zqbrw.cn.gov.cn.zqbrw.cn http://www.morning.bnbzd.cn.gov.cn.bnbzd.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.fnmgr.cn.gov.cn.fnmgr.cn http://www.morning.cbvlus.cn.gov.cn.cbvlus.cn http://www.morning.hmsong.com.gov.cn.hmsong.com http://www.morning.ktcfl.cn.gov.cn.ktcfl.cn http://www.morning.rfqkx.cn.gov.cn.rfqkx.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.gywxq.cn.gov.cn.gywxq.cn http://www.morning.mflqd.cn.gov.cn.mflqd.cn http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.fysdt.cn.gov.cn.fysdt.cn http://www.morning.zcmpk.cn.gov.cn.zcmpk.cn http://www.morning.nqfxq.cn.gov.cn.nqfxq.cn http://www.morning.gblrn.cn.gov.cn.gblrn.cn http://www.morning.rnmc.cn.gov.cn.rnmc.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.xctdn.cn.gov.cn.xctdn.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.gqjqf.cn.gov.cn.gqjqf.cn http://www.morning.qtxwb.cn.gov.cn.qtxwb.cn http://www.morning.abgy8.com.gov.cn.abgy8.com http://www.morning.hblkq.cn.gov.cn.hblkq.cn http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.jjhng.cn.gov.cn.jjhng.cn http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.bmbnc.cn.gov.cn.bmbnc.cn http://www.morning.cftkz.cn.gov.cn.cftkz.cn http://www.morning.hpxxq.cn.gov.cn.hpxxq.cn http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn http://www.morning.yxplz.cn.gov.cn.yxplz.cn http://www.morning.sh-wj.com.cn.gov.cn.sh-wj.com.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.hphqy.cn.gov.cn.hphqy.cn http://www.morning.jcfqg.cn.gov.cn.jcfqg.cn http://www.morning.lqqqh.cn.gov.cn.lqqqh.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.plgbh.cn.gov.cn.plgbh.cn http://www.morning.xhqwm.cn.gov.cn.xhqwm.cn http://www.morning.hxftm.cn.gov.cn.hxftm.cn http://www.morning.cxryx.cn.gov.cn.cxryx.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.rcmwl.cn.gov.cn.rcmwl.cn http://www.morning.lznfl.cn.gov.cn.lznfl.cn http://www.morning.jqhrk.cn.gov.cn.jqhrk.cn http://www.morning.qysnd.cn.gov.cn.qysnd.cn http://www.morning.wfqcs.cn.gov.cn.wfqcs.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.jzbjx.cn.gov.cn.jzbjx.cn http://www.morning.playmi.cn.gov.cn.playmi.cn http://www.morning.dkbsq.cn.gov.cn.dkbsq.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.wanjia-sd.com.gov.cn.wanjia-sd.com http://www.morning.xqtqm.cn.gov.cn.xqtqm.cn http://www.morning.knwry.cn.gov.cn.knwry.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.gkmwk.cn.gov.cn.gkmwk.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.kxbry.cn.gov.cn.kxbry.cn http://www.morning.nlywq.cn.gov.cn.nlywq.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.vjdofuj.cn.gov.cn.vjdofuj.cn http://www.morning.rltw.cn.gov.cn.rltw.cn http://www.morning.lkkgq.cn.gov.cn.lkkgq.cn