1、java工程,且是utf-8的编码;
2、mysql,utf-8编码;
3、插入中文,在数据库显示成??
4、如果加上useUnicode=true&characterEncoding=utf-8,则报如下错误
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xE5\x9B\xBD1\xE5\xAE...' for column 'name' at row 1。
2016-12-15 14:38:33.430 DEBUG [main] Database info --> MYSQL:[MySQL - 5.5.5-10.1.19-MariaDB]
2016-12-15 14:38:33.523 DEBUG [main] INSERT INTO t_person(name,age) VALUES(?,?)
| 1 | 2 |
|------|----|
| 中1国a | 20 |
For example:> "INSERT INTO t_person(name,age) VALUES('中1国a',20) "
2016-12-15 14:38:33.532 DEBUG [main] SQLException
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:159)
at com.ljlpay.test.Test.main(Test.java:24)
2016-12-15 14:38:33.534 INFO [main] org.nutz.ioc.impl.NutIoc@175408781 is closing. startup date [16-12-15 14:38:33.037]
2016-12-15 14:38:33.534 DEBUG [main] Depose object 'dataSource' ...
十二月 15, 2016 2:38:33 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} closed
2016-12-15 14:38:33.538 INFO [main] org.nutz.ioc.impl.NutIoc@175408781 is deposed. startup date [16-12-15 14:38:33.037]
Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO t_person(name,age) VALUES('中1国a',20) '
PreparedStatement:
'INSERT INTO t_person(name,age) VALUES(?,?) '
CaseMessage=Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:159)
at com.ljlpay.test.Test.main(Test.java:24)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
... 13 more
纯英文可以插入。
jdbc:mysql://127.0.0.1:3306/test,这样写也可以插入汉字,但是成了问号。
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8 这样写,就是上面报的错误了。
我的myeclipse,数据库,工程统统是UTF-8的
public static void main(String[] args) {
Ioc ioc = null;
try {
ioc = new NutIoc(new JsonLoader("db.js"));
DataSource ds = ioc.get(DataSource.class);
Dao dao = new NutDao(ds);
Person p = new Person();
p.setName("中1国a");
p.setAge(20);
dao.insert(p);
} finally {
ioc.depose();
}
}
{
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
depose : 'close'
},
fields : {
driverClassName : "com.mysql.jdbc.Driver",
url : "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8",
username : "root",
password : "123456",
maxWait: 15000, // 若不配置此项,如果数据库未启动,druid会一直等可用连接,卡住启动过程,
defaultAutoCommit : false // 提高fastInsert的性能
}
}
}
2016-12-15 14:54:53.749 WARN [main] !!You are using default SystemLog! Don't use it in Production environment!!
2016-12-15 14:54:53.956 DEBUG [main] Locations for Scans:
[Dir[path=D:\myeclipse\workspace\myeclipse2016ci7\Nutz1], Jar[path=D:\myeclipse\workspace\myeclipse2016ci7\Nutz1\lib\nutz-1.r.58.jar], Dir[path=D:\myeclipse\workspace\myeclipse2016ci7\Nutz1\bin], Jar[path=D:\myeclipse\workspace\myeclipse2016ci7\Nutz1\lib\druid-1.0.26.jar], Jar[path=D:\myeclipse\workspace\myeclipse2016ci7\Nutz1\lib\mysql-connector-java-5.1.40.jar]]
2016-12-15 14:54:53.960 DEBUG [main] Found 1 resource by src( db.js ) , regex( ^(.+[.])(js|json)$ )
2016-12-15 14:54:53.961 DEBUG [main] loading ioc js config from [db.js]
2016-12-15 14:54:54.7 DEBUG [main] Using 94 castor for Castors
2016-12-15 14:54:54.10 DEBUG [main] Loaded 1 bean define from path=[db.js] --> [dataSource]
2016-12-15 14:54:54.13 INFO [main] NutIoc init begin ...
2016-12-15 14:54:54.15 INFO [main] ... NutIoc init complete
2016-12-15 14:54:54.17 DEBUG [main] Get 'dataSource'<interface javax.sql.DataSource>
2016-12-15 14:54:54.20 DEBUG [main] Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
2016-12-15 14:54:54.20 DEBUG [main] >> Load definition name=dataSource
2016-12-15 14:54:54.21 DEBUG [main] Loading define for name=dataSource
2016-12-15 14:54:54.31 DEBUG [main] Found IocObject(dataSource) in JsonLoader(paths=[db.js])
2016-12-15 14:54:54.32 DEBUG [main] >> Make...'dataSource'<interface javax.sql.DataSource>
2016-12-15 14:54:54.45 DEBUG [main] Load class com.alibaba.druid.pool.DruidDataSource without AOP
2016-12-15 14:54:54.46 DEBUG [main] Save object 'dataSource' to [app]
2016-12-15 14:54:54.82 DEBUG [main] NutDao[_selfId=0] init ...
2016-12-15 14:54:54.104 INFO [main] Init file-pool by: C:\Users\hasee/.nutz/tmp/dao/ [200000]
2016-12-15 14:54:54.104 DEBUG [main] file-pool.home: 'C:\Users\hasee\.nutz\tmp\dao'
2016-12-15 14:54:54.106 INFO [main] file-pool.cursor: 0
2016-12-15 14:54:54.115 DEBUG [main] Jdbcs init complete
2016-12-15 14:54:54.115 INFO [main] Get Connection from DataSource for JdbcExpert, if I lock at here, check your database server and configure
十二月 15, 2016 2:54:54 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
2016-12-15 14:54:54.402 DEBUG [main] JDBC Driver --> mysql-connector-java-5.1.40 ( Revision: 402933ef52cad9aa82624e80acbea46e3a701ce6 )
2016-12-15 14:54:54.402 DEBUG [main] JDBC Name --> MySQL Connector Java
2016-12-15 14:54:54.402 DEBUG [main] JDBC URL --> jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
2016-12-15 14:54:54.412 DEBUG [main] Mysql : character_set_client=utf8
2016-12-15 14:54:54.412 DEBUG [main] Mysql : character_set_connection=utf8
2016-12-15 14:54:54.412 DEBUG [main] Mysql : character_set_database=utf8
2016-12-15 14:54:54.413 DEBUG [main] Mysql : character_set_filesystem=binary
2016-12-15 14:54:54.413 DEBUG [main] Mysql : character_set_results=
2016-12-15 14:54:54.413 DEBUG [main] Mysql : character_set_server=latin1
2016-12-15 14:54:54.413 DEBUG [main] Mysql : character_set_system=utf8
2016-12-15 14:54:54.414 DEBUG [main] Mysql : character_sets_dir=D:\mariadb-10.1.19-winx64\share\charsets\
2016-12-15 14:54:54.414 DEBUG [main] Mysql : database=test
2016-12-15 14:54:54.415 DEBUG [main] Mysql : user=root@localhost
2016-12-15 14:54:54.428 DEBUG [main] Database info --> MYSQL:[MySQL - 5.5.5-10.1.19-MariaDB]
2016-12-15 14:54:54.527 DEBUG [main] INSERT INTO t_person(name,age) VALUES(?,?)
| 1 | 2 |
|------|----|
| 中1国a | 20 |
For example:> "INSERT INTO t_person(name,age) VALUES('中1国a',20) "
2016-12-15 14:54:54.535 DEBUG [main] SQLException
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:159)
at com.ljlpay.test.Test.main(Test.java:24)
2016-12-15 14:54:54.537 INFO [main] org.nutz.ioc.impl.NutIoc@175408781 is closing. startup date [16-12-15 14:54:54.013]
2016-12-15 14:54:54.538 DEBUG [main] Depose object 'dataSource' ...
十二月 15, 2016 2:54:54 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} closed
2016-12-15 14:54:54.542 INFO [main] org.nutz.ioc.impl.NutIoc@175408781 is deposed. startup date [16-12-15 14:54:54.013]
Exception in thread "main" org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO t_person(name,age) VALUES('中1国a',20) '
PreparedStatement:
'INSERT INTO t_person(name,age) VALUES(?,?) '
CaseMessage=Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:266)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:274)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:159)
at com.ljlpay.test.Test.main(Test.java:24)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xE4\xB8\xAD1\xE5\x9B...' for column 'name' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:308)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
... 13 more
CREATE TABLE t_person
(
id
bigint(20) unsigned NOT NULL AUTO_INCREMENT,
name
varchar(20) NOT NULL,
age
int(11) DEFAULT NULL,
PRIMARY KEY (id
),
UNIQUE KEY name
(name
)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8
2016-12-15 15:21:16,456 org.nutz.dao.util.DaoUp.buildDataSource(DaoUp.java:199) DEBUG - build DruidDataSource by props
2016-12-15 15:21:16,560 org.nutz.castor.Castors.reload(Castors.java:115) DEBUG - Using 94 castor for Castors
2016-12-15 15:21:16,577 org.nutz.dao.impl.NutDao.<init>(NutDao.java:108) DEBUG - NutDao[_selfId=0] init ...
2016-12-15 15:21:16,615 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:23) INFO - Init file-pool by: C:\Users\wendal/.nutz/tmp/dao/ [200000]
2016-12-15 15:21:16,616 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:37) DEBUG - file-pool.home: 'C:\Users\wendal\.nutz\tmp\dao'
2016-12-15 15:21:16,626 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:66) INFO - file-pool.cursor: 1764
2016-12-15 15:21:16,634 org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:90) DEBUG - Jdbcs init complete
2016-12-15 15:21:16,634 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103) INFO - Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
2016-12-15 15:21:16,736 com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:715) INFO - {dataSource-1} inited
2016-12-15 15:21:16,964 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:198) DEBUG - JDBC Driver --> mysql-connector-java-5.1.40 ( Revision: 402933ef52cad9aa82624e80acbea46e3a701ce6 )
2016-12-15 15:21:16,964 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:199) DEBUG - JDBC Name --> MySQL Connector Java
2016-12-15 15:21:16,964 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:201) DEBUG - JDBC URL --> jdbc:mysql://127.0.0.1/nutztest?zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8
2016-12-15 15:21:16,972 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_client=utf8
2016-12-15 15:21:16,972 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_connection=utf8
2016-12-15 15:21:16,972 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_database=utf8
2016-12-15 15:21:16,972 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_filesystem=binary
2016-12-15 15:21:16,973 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_results=
2016-12-15 15:21:16,974 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_server=utf8
2016-12-15 15:21:16,974 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_system=utf8
2016-12-15 15:21:16,974 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_sets_dir=C:\Program Files\MariaDB 10.1\share\charsets\
2016-12-15 15:21:16,976 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:219) DEBUG - Mysql : binlog_format=STATEMENT
2016-12-15 15:21:16,977 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:226) DEBUG - Mysql : database=nutztest
2016-12-15 15:21:16,977 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:232) DEBUG - Mysql : user=root@localhost
2016-12-15 15:21:16,990 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:220) DEBUG - Database info --> MYSQL:[MySQL - 5.5.5-10.1.19-MariaDB]
2016-12-15 15:21:17,210 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - DROP TABLE tx_daoup_user
2016-12-15 15:21:17,213 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - create table tx_daoup_user (id int, nm varchar(50), age int)
2016-12-15 15:21:17,259 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO tx_daoup_user(id,nm,age) VALUES(?,?,?)
| 1 | 2 | 3 |
|---|----|----|
| 5 | 中文 | 10 |
For example:> "INSERT INTO tx_daoup_user(id,nm,age) VALUES(5,'中文',10) "
2016-12-15 15:21:17,262 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT COUNT(*) FROM tx_daoup_user
2016-12-15 15:21:17,266 org.nutz.dao.util.DaoUp.close(DaoUp.java:217) INFO - shutdown DaoUp(name=_defult_)
2016-12-15 15:21:17,269 com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:1444) INFO - {dataSource-1} closed
各位,不报错了,还是得加上utf-8,我快放弃的时候,自动好了。我清理过了,应该不存在编译问题
jdbc:mysql://127.0.0.1:3306/nutz?useUnicode=true&characterEncoding=UTF-8
测试结果:
my.ini不加character_set_server=utf8, jdbcurl不加characterEncoding, 插入不报错, 数据库乱码
my.ini加character_set_server=utf8, jdbcurl不加characterEncoding, 插入不报错, 数据库正常
my.ini不加character_set_server=utf8, jdbcurl加characterEncoding, 插入不报错, 数据库正常
我至今没测出能抛异常的情况
PS: my.ini 改完均重启mysql服务