I use of following query in ormlite with Mysql:
String _textSearch="%اعصاب%";
Where<QuestionEntity, Long> _where= getDao().queryBuilder()).where();
List<QuestionEntity> _lst= _where.or(_where.like("title",_textSearch ),
_where.like("questiontext", _textSearch)).query();
but generate following query:
SELECT * FROM `question`
WHERE (`title` LIKE '%?????%' OR `questiontext` LIKE '%?????%' )
why ?
SELECT * FROM `question`
WHERE (`title` LIKE '%?????%' OR `questiontext` LIKE '%?????%' )
Hrm, I'm not sure what the problem is here. I've added the this UTF8 query-build test to the ormlite-core project and it passes fine.
Foo foo = new Foo();
foo.stringField = "اعصاب";
dao.create(foo);
List<Foo> results = dao.queryBuilder().where()
.like(Foo.STRING_COLUMN_NAME, foo.stringField).query();
assertEquals(foo.stringField, results.get(0).stringField);
This generates the following log output:
SELECT * FROM `foo` WHERE `string` LIKE 'اعصاب'
This also works with a SelectArg
which is how ORMLite does ?
args.
statement arguments: [اعصاب]
SELECT * FROM `foo` WHERE `string` LIKE ?
I initially thought that this was a problem with MySQL. Maybe you got the queries out of the server log? If you got the '?????' from a local log then I'm not sure what the issue is. Maybe the default character encoding for your application?
The tests are using H2 which is a native Java DB so can easily handle Java's strings. Maybe take a look at these MySQL questions/answers for help:
There is some talk about later versions of the MySQL connector fixing a problem with detecting the character type of the database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.