mysql建表时指定编码,避免Data too long for column.....的异常
2011-11-05 21:23
441 查看
有时候需要在程序中动态的创建数据库表(如日志表,可以动态的分年分月创建,以保证单张表数据不会太大),如果这是使用的是mysql数据库,需要在创建表的ddl语句末尾加上字符编码如:ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COMMENT='数据采集日志',否则创建出来的表的各字段的编码可能会是latin1,从而在保存有中文字符的数据时会报 Data too long for column....的异常。
完整的创建表语句:
create table GCL_${tableNameSuffix} (
SOURCEID VARCHAR(70) not null,
ID VARCHAR(36),
STATUS VARCHAR(4),
MARK VARCHAR(3000),
DATASETTIME DATETIME,
UPDATETIME DATETIME,
constraint PK_GCL_${tableNameSuffix} primary key (SOURCEID)
)ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COMMENT='数据采集日志'
完整的创建表语句:
create table GCL_${tableNameSuffix} (
SOURCEID VARCHAR(70) not null,
ID VARCHAR(36),
STATUS VARCHAR(4),
MARK VARCHAR(3000),
DATASETTIME DATETIME,
UPDATETIME DATETIME,
constraint PK_GCL_${tableNameSuffix} primary key (SOURCEID)
)ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 COMMENT='数据采集日志'
相关文章推荐
- Data too long for column 'name' at row 1 mysql的抛出异常的解决办法--之前方法不管用-要设置数据库编码
- 数据库编码com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'sex' at row 1
- Data too long for column 'name' at row 1 mysql的抛出异常的解决办法
- 读取MYSQL中文数据乱码,解决data too long for column 'title' at row 1
- mysql中data too long for column问题的解决方法
- mysql data too long for column xxx解决方案
- Mysql 中ERROR 1406 (22001): Data too long for column
- DBD::mysql::st execute failed: Data too long for column...解决办法之一
- MySql学习之 Data Too long for column bit
- MySql 弹出“data too long for column 'xxx' at row 1"解决方法
- MySql的Blob字段报错:Data truncation: Data too long for column 'CONTENT' at row 1
- Mysql MysqlDataTruncation Data truncation Data too long for column
- Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'content' at ro
- MySql的Blob字段报错:Data truncation: Data too long for column 'CONTENT' at row 1
- Mysql——Data too long for column \'表名\' at ...
- com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1
- Eexception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'PIC' at
- ### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column \'name\' at row 1
- sql点滴37—mysql中的错误Data too long for column '' at row 1
- Mysql "data too long for column"