In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the example analysis of MySql super-long automatic truncation, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
As follows
CREATE TABLE `pSecretappappstation` (`WX_APP_ ID` varchar (20) NOT NULL, `IS_ SECRET` varchar (33) DEFAULT NULL, `IS_ BINDING` int (1) DEFAULT '0such, `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 `ACTIVE_ ID`varchar (13) DEFAULT NULL, `STATION_ type` int (1) unsigned zerofill DEFAULT NULL COMMENT 'tag type (trial version: 0, member version: 1, customized version: 2)', `ACTIVE_ DATE`datetime DEFAULT NULL COMMENT 'expiration time', `APP_MODULE_ ID`varchar (60) DEFAULT NULL COMMENT 'push template message ID', PRIMARY KEY (`WX_APP_ ID`) ENGINE=InnoDB DEFAULT CHARSET=utf8insert into p_app_station (wx_app_id) values (' 12121312312312 ah aassasdasd') Select * from p_app_station where wx_app_id like '12121312312312%'
Obviously, the varchar (20) is not enough to accommodate 12121312312312 aassasdasd.
The query results are as follows
It is true that it is automatically truncated, but performing the same sql in the project is not the case. Instead, an error is reported.
Data truncated for column's'at row ld
Considering that it is the same database and there is no different schema, then the possibility should appear on the jdbcDriver.
View the jdbc source code
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}
View the getJdbcCompliantTruncation method, whose default value is
Private BooleanConnectionProperty jdbcCompliantTruncation = new BooleanConnectionProperty ("jdbcCompliantTruncation", true, Messages.getString ("ConnectionProperties.jdbcCompliantTruncation"), "3.1.2", MISC_CATEGORY, Integer.MIN_VALUE)
Therefore, if jdbcCompliantTruncation is not set in jdbcurl from version 3.1.2, no truncation will be performed by default and an error will be reported.
So is it okay to add parameters?
A trade-off:
If truncation occurs when the ratio is too long, there may be a risk of loss of accuracy.
Therefore, it is recommended to check it in the program.
Currently working on using hibernate validate.
Thank you for reading this article carefully. I hope the article "sample Analysis of MySql Ultra-long automatic truncation" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.