我有这个方法:
@Override
public List<Biblioteczka> wyswietlenieKsiazek() throws SQLException
{
Dao<Biblioteczka,String>biblioteczkaDao=DaoManager.createDao(connectionSource,Biblioteczka.class);
Where<Biblioteczka,String>queryBuilder=biblioteczkaDao.queryBuilder().where().eq("Rodzaj","Książka");
PreparedQuery<Biblioteczka>preparedQuery=queryBuilder.prepare();
List<Biblioteczka>lista=biblioteczkaDao.query(preparedQuery);
return lista;
}
它应该执行此查询:
select * from Zbiory where Rodzaj="Książka"
但OrmLite不理解“Książka”这个词(因为“ą”和“ż”)所以我有0个结果:
2015-06-04 20:11:21,456 [DEBUG] DaoManager created dao for class class Biblioteczka with reflection
2015-06-04 20:11:21,468 [DEBUG] StatementBuilder built statement SELECT * FROM `Zbiory` WHERE `Rodzaj` = 'Książka'
2015-06-04 20:11:21,807 [DEBUG] JdbcConnectionSource opened connection to jdbc:mysql://localhost:3306/Biblioteka got #914810065
2015-06-04 20:11:21,823 [DEBUG] BaseMappedStatement prepared statement 'SELECT * FROM `Zbiory` WHERE `Rodzaj` = 'Książka' ' with 0 args
2015-06-04 20:11:21,827 [DEBUG] SelectIterator starting iterator @479233124 for 'SELECT * FROM `Zbiory` WHERE `Rodzaj` = 'Książka' '
2015-06-04 20:11:21,828 [DEBUG] SelectIterator closed iterator @479233124 after 0 rows
2015-06-04 20:11:21,828 [DEBUG] StatementExecutor query of 'SELECT * FROM `Zbiory` WHERE `Rodzaj` = 'Książka' ' returned 0 results
2015-06-04 20:11:22,558 [DEBUG] JdbcConnectionSource closed connection #914810065
如何解决这个问题? 我正在使用MySQL。默认排序规则:utf8_general_ci,默认字符集:utf8,表排序规则:utf8_general_ci。
答案 0 :(得分:0)
嗯,您的应用程序和数据库都理解UTF-8。你的DB驱动程序怎么样?确保MySQL的连接字符串(假设您根据您提供的日志使用MySQL)包含characterEncoding
和useUnicode
参数
jdbc:mysql://server:post/deName?useUnicode=true&characterEncoding=UTF-8
如果这没有帮助,你可以尝试重型机械
character_set_client=UTF-8&character_set_database=UTF-8&character_set_results=UTF8&character_set_server=UTF-8&character_set_system=UTF-8
最后使用
初始化数据库连接set names utf8
还要确保所有源文件实际上都是UTF-8。
希望有所帮助!