Stringsql="insertintoemp(ename,job,hiredate)values('"+ename+"','"+job+"','"+hiredate+"')";//SQL语句是这个insertintoemp(ename,job,hiredate)values('王跃青','助理','2001-09-...
String sql = "insert into emp(ename,job,hiredate) values('" + ename+ "','" + job + "','" + hiredate + "')";
//SQL语句是这个insert into emp(ename,job,hiredate) values('王跃青','助理','2001-09-19')
System.out.println(sql.getBytes(Charset.forName("GBK")).length);
//72
System.out.println(sql.getBytes(Charset.forName("UTF-8")).length);
//77
System.out.println(sql.getBytes().length);
//72 和GBK的长度一样应该是GBK编码没有错。
System.out.println(sql);
s.executeUpdate(sql);
-------------------------------------------------------------------------------------
接下来是表。
CREATE TABLE `NewTable` (
`empno` smallint(4) NOT NULL AUTO_INCREMENT ,
`ename` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL ,
`job` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL ,
`hiredate` date NULL DEFAULT NULL ,
PRIMARY KEY (`empno`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=gbk COLLATE=gbk_chinese_ci
AUTO_INCREMENT=1082
ROW_FORMAT=COMPACT;
为什么输入进去是乱码。
展开