国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

MySql超長(zhǎng)自動(dòng)截?cái)鄬?shí)例詳解

2024-07-24 13:14:03
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

MySql超長(zhǎng)自動(dòng)截?cái)鄬?shí)例詳解

小伙伴問(wèn)到一個(gè)問(wèn)題,為啥在項(xiàng)目中調(diào)用插入或者更新語(yǔ)句時(shí)超長(zhǎng)的字無(wú)法自動(dòng)截?cái)啵趎avicat中直接執(zhí)行是可以自動(dòng)截?cái)嗟模?/p>

如下

CREATE TABLE `p_app_station` ( `WX_APP_ID` varchar(20) NOT NULL, `APP_SECRET` varchar(33) DEFAULT NULL, `IS_BINDING` int(1) DEFAULT '0', `ACCOUNT_ID` int(13) DEFAULT NULL, `TOKEN` varchar(40) DEFAULT NULL, `BIND_URL` varchar(200) DEFAULT NULL, `WX_APP_NAME` varchar(50) DEFAULT NULL, `WX_APP_SID` varchar(50) DEFAULT NULL, `WX_NO` varchar(50) DEFAULT NULL, `CREATE_USER_ID` varchar(13) DEFAULT NULL, `UPDATE_DATE` datetime DEFAULT NULL, `CREATE_DATE` datetime DEFAULT NULL, `UPDATE_USER_ID` varchar(13) DEFAULT NULL, `STATION_TYPE` int(1) unsigned zerofill DEFAULT NULL COMMENT '標(biāo)記類型(試用版:0,會(huì)員版:1,定制版:2)', `ACTIVE_DATE` datetime DEFAULT NULL COMMENT '使用時(shí)間截止', `APP_MODULE_ID` varchar(60) DEFAULT NULL COMMENT '推送模版消息ID', PRIMARY KEY (`WX_APP_ID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
insert into p_app_station(wx_app_id) values('12121312312312啊啊啊啊啊aassasdasd');select * from p_app_station where wx_app_id like '12121312312312%';

很明顯varchar(20) 不足以容納12121312312312啊啊啊啊啊aassasdasd

查詢結(jié)果如下

 Mysql,自動(dòng)截?cái)?自動(dòng)截?cái)鄬?shí)例詳解

確實(shí)自動(dòng)截?cái)嗔耍窃陧?xiàng)目中執(zhí)行同樣的sql發(fā)現(xiàn)并非如此,反而報(bào)錯(cuò)。

Data truncated for column '%s' at row %ld

考慮到是同一個(gè)數(shù)據(jù)庫(kù),不存在模式不同,那么可能性應(yīng)該出現(xiàn)在jdbcDriver上。

查看jdbc源碼

private void setupServerForTruncationChecks() throws SQLException {  if (getJdbcCompliantTruncation()) {    if (versionMeetsMinimum(5, 0, 2)) {      String currentSqlMode = this.serverVariables.get("sql_mode");       boolean strictTransTablesIsSet = StringUtils.indexOfIgnoreCase(currentSqlMode, "STRICT_TRANS_TABLES") != -1;       if (currentSqlMode == null || currentSqlMode.length() == 0 || !strictTransTablesIsSet) {        StringBuilder commandBuf = new StringBuilder("SET sql_mode='");         if (currentSqlMode != null && currentSqlMode.length() > 0) {          commandBuf.append(currentSqlMode);          commandBuf.append(",");        }         commandBuf.append("STRICT_TRANS_TABLES'");         execSQL(null, commandBuf.toString(), -1, null, DEFAULT_RESULT_SET_TYPE, DEFAULT_RESULT_SET_CONCURRENCY, false, this.database, null, false);         setJdbcCompliantTruncation(false); // server's handling this for us now      } else if (strictTransTablesIsSet) {        // We didn't set it, but someone did, so we piggy back on it        setJdbcCompliantTruncation(false); // server's handling this for us now      }     }  }}

查看getJdbcCompliantTruncation方法,其默認(rèn)值為

private BooleanConnectionProperty jdbcCompliantTruncation = new BooleanConnectionProperty("jdbcCompliantTruncation", true,    Messages.getString("ConnectionProperties.jdbcCompliantTruncation"), "3.1.2", MISC_CATEGORY, Integer.MIN_VALUE);

因此從3.1.2版本在jdbcurl中如果沒(méi)有設(shè)置jdbcCompliantTruncation那么默認(rèn)將會(huì)執(zhí)行不截?cái)嗖⑶覉?bào)錯(cuò)。

那么加上參數(shù)是否可以呢?

取舍一下:

如果截?cái)喈?dāng)出現(xiàn)比超長(zhǎng)可能會(huì)有精度丟失的風(fēng)險(xiǎn)。

因此建議還是在程序中檢查。

目前正在做關(guān)于使用hibernate validate的相關(guān)。

以上就是關(guān)于MySQL 截?cái)嗟闹v解,大家如有疑問(wèn)可以留言或者到本站社區(qū)交流討論,共同進(jìn)步, 感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到MYSQL教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青河县| 忻州市| 岐山县| 江川县| 平山县| 石嘴山市| 沙雅县| 抚顺市| 河源市| 茶陵县| 奉化市| 拉萨市| 麦盖提县| 灵寿县| 孝昌县| 弥渡县| 曲阳县| 西吉县| 九龙坡区| 板桥市| 柳州市| 榆中县| 延边| 永城市| 西盟| 铅山县| 色达县| 四子王旗| 原阳县| 津市市| 曲阜市| 钦州市| 桦甸市| 淮阳县| 定兴县| 勐海县| 泸定县| 普安县| 子长县| 彩票| 上杭县|