开始之前,对不起我的英文。MySQL数据库编码
我有一个MySQL的问题。我创建数据库,并将编码字符串更改为latin2。从Java查询:
`INSERT INTO infos VALUES (NULL, '100001486491198', 'ęłóżźćść[email protected]#', '2013-12-23 11:24:37', 0, 0, 0);`
在数据库中看起来像“???????”。我在phpMyAdmin中将此字符串更改为targen,并且当我执行SELECT查询时,我得到相应的字符串作为响应。
而且我这个代码添加到数据库连接:
Properties properties = new Properties();
properties.put("user", DBUSER);
properties.put("password", DBPASS);
properties.put("characterEncoding", "ISO-8859-2");
properties.put("useUnicode", "true");
try {
Class.forName(DBDRIVER).newInstance();
connection = DriverManager.getConnection(DBURL, properties);
statement = connection.createStatement();
}
catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
但作为回应,我得到错误:
java.sql.SQLException: Incorrect string value: '\xB3\xF3\xBF\xBC\xE6\xBF...' for column 'content' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2812)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at com.mpkinfo.server.database.Database.add(Database.java:48)
...
什么,我做错了什么?
我想你应该选择UTF8斌,编码你所有的mysql表格。 –