I have MySQL InnoDB table utf-8 encoded. This table has only id and name field. Names are in russian language and 1 name in English for testing purpose. English name selects ok but when trying to select with russian name it returns empty list. I tried to build queries both with Criterion and HQL.
getHibernateTemplate().find("from FirstName where name='free' ");
getHibernateTemplate().find("from FirstName where name='ИННА' ");
Here is connection string -
?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8
i'm using hibernate 3.2.7.ga and spring 2.5.6.SEC03
Here is hibernate log:
Hibernate: /* from FirstName where name='ИННА' */ select firstname0_.`id` as id1_24_, firstname0_.`name` as name2_24_ from `first_name` firstname0_ where firstname0_.`name`='ИННА' limit ?
Thanks to all, i have found an answer.
The problem was in connection string.
I did refactor and moved connection string to the properties file instead of xml with spring-bean. But i did not changed "&" entity to the "&".
Successfull connection string is in properties file
jdbc:mysql://${host}:${port}/${database}?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
XML file changes & entities to the correct, but properties format don't do this.
Criteria coCriteria = Session.createCriteria(coClass).add(Restrictions.eq(strColumnName, strColumnValue));
list = coCriteria.list();
Did you try with this hibernate criteria.
Where "Session" will the session object of hibernate generated session.
1)coClass = "pojo class name"
2)strColumnName = "pojo class field name" in your case it will be "name" i guess
3)strColumnValue = in your case it will be "ИННА"
Did you try changing the character encoding at database level?
According to MySQL documentation, Cyrillic characters are supported with "cp1251"
You may take a look at this link as well
Related
I have been using UCanAccess to use Access databases my problem is when i want to delete a recor this returns automatically.
For example if i have:
Table Names
Id Name
1 Jessy
2 Abraham
String deleteQuery = "DELETE From Names where Id =?";
PreparedStatement pstm = con.getConnection().prepareStatement(deleteQuery);
pstm.setInt(1, 1); // "id" is type numeric
pstm.executeUpdate();
pstm.close();
it will works And then if i open the database the recor will be there!
that's my problem. (i hide the connection code but i have it)
Try to use compact feature provided by Access. On the Tools menu, point to Database Utilities, and then click Compact and Repair Database. This might help.
Do you do the commit after? If not and autocommit=false, just do it.
I found the problem, I was using data type OLE to save images simple sentences doesn't works so the way to delete a row with OLE field is creating Database and Table objects from java. It works.
Hi I'm trying to use collate on a view which has column name per_va_first_name when I use the following query :
SELECT *
FROM person_view
WHERE NLSSORT(per_va_first_name, 'NLS_SORT = FRENCH_AI') = NLSSORT('mickaël', 'NLS_SORT =FRENCH_AI')
I get the error
ORA-12702: invalid NLS parameter string used in SQL function
I'm new to oracle and this nlssort. Can anyone help me in pointing out what's my mistake?
And at the same time I want to use collate in Hibernate for Java. Same french char set.
Edit:
When I use these commands in sql
alter session set nls_sort=French_AI;
alter session set nls_comp=linguistic;
I get the desired output when this query is executed
SELECT * FROM v_myuser_search_test_ea4 where per_va_first_name like 'Mickaël%'
How to do this in Hibernate? Is there a way I can append 'CI' to French_AI to make it 'French_AI_CI'
According to Oracle documentation found on http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions113.htm#SQLRF51562
you might change your query to
SELECT *
FROM person_view
ORDER BY NLSORT(per_va_first_name, 'NLS_SORT = FRENCH_AI_CI')
Hibernate should understand it, however you are already losing database portability as this is Oracle-specific function.
I am using JDBC to get data out of a file maker server v12.
For some unknown reason filemaker allows you to have spaces in your table names. I am unable to select these tables because I just get a syntax error.
I have written an application in java to get the data out. Does anyone have any idea how i can select the data from a table with a space in it?
EDIT (from OP's comments):
This is the Java part:
String selectSQL = "SELECT "+this.getImportableColumnsString()+" FROM "+this.getTableName();
PreparedStatement preparedStatement = this.connection.prepareStatement(selectSQL);
ResultSet rs = preparedStatement.executeQuery();
As mentioned in a comment to the question, if the FileMaker table name contains spaces then it must be enclosed in double-quotes in the SQL statement, e.g.,
String selectSQL = "SELECT * FROM \"table name\"";
My first thought is that you could put the table name within ' characters like: SELECT * FROM 'my table'. Does this not work?
Otherwise I suggest you contact the Filemaker Server support on this page:
http://help.filemaker.com/app/ask
It is likely that they have had this question before and knows how to build the query.
//Flipbed
I'm pretty sure in the docs for OCDB and JDBC support FileMaker says that tables may have to comply to naming conventions that are stricter than what FileMaker allows. It is easy to change table names in FileMaker if you have admin access to the database you are sourcing why not just replace the spaces in the table names with underscores.
I am using mysql query browser to store the following names in the Person table which contains fields of personNumber and personName. I have the character set of personName at utf-8 and if i insert the name via query browse the query is running correctly but when i try that via JDBC or JPA, the name's special characters become the '?'. What is the problem here?...
The names are
1.Năstase
2.Hrustanović
3.Ogris-Martič and some similar names.
Have you set your connection string correctly?
jdbc:mysql://localhost:3306/administer?characterEncoding=utf8
Try this code
jdbc:mysql://localhost:3306/MY_DB?useUnicode=yes&characterEncoding=UTF8
I have a problem while selecting from a table containg data in utf-8 format in MySQL using java, in the WHERE clause I need to compare if a column value equals to a java String but they don't match
"Select age from student where name = '"+stringVariable+"';"
the stringVariable can sometimes be in arabic so in this case they don't match
The database is utf8mb4 and the connection also between java and database is utf_8 and I dont have a problem while inserting or just selecting data but the problem occurs while comparing
I tried to convert the string like this and it also didnt match
byte[] b = stringVariable.getBytes("UTF-8");
String str = new String(b,"UTF-8");
So anyone has any solution for that ?!
Thank you in advance
Use parameters. The driver should then encode them correctly according to the connection properties.
PreparedStatement statement = connection.prepareStatement(
"select age from student where name = ?");
statement.setString(1, stringVariable);
In addition, this also correctly escapes special SQL characters (like single quotes).
You shouldn't have to transform anything. The driver takes care of everything. Try using a prepared statement rather than string concatenation. This will have the additional advantage of avoiding SQL injection attacks, and make sure your statement works even if the string variable contains a quote.
I solved this problem it was not only related with the database query but I get the string from ajax request so I had to decode it from utf8 first and then get the parameter value using
URLDecoder.decode(request.getQueryString(), "UTF-8")
and then pass it to the query and I used prepared statement which encodes it according to the connection properties as you mentioned
Thank you