开发者

Problem with special characters and preparedStatement, ONLY if I use setString

I've read many threads regarding this topic, but everybody point to the character set in the database.

I'm using strings wit开发者_运维问答h special characters like 'ñ' and I'm not able to set them right in the database. As you may guess, the characters are changed to '?'.

The thing is that using this statement, I get it RIGHT:

stmt = con.prepareStatement("INSERT INTO LONG_CODES_TABLE (TIMESTAMP, TABLE_NAME, CODE__C, CODE_DESC) 
VALUES (GET_TIMESTAMP, 'MUNICIPIOS', '" + municipio + "',  '" + municipio + "') ");

And just in the same database and table, without changing anything, if I use the following I get the '?' character in the DB:

stmt = con.prepareStatement("INSERT INTO LONG_CODES_TABLE (TIMESTAMP, TABLE_NAME, CODE__C, CODE_DESC) 
VALUES (GET_TIMESTAMP, 'MUNICIPIOS', ?,  ?) ");

stmt.setString(1, municipio);

stmt.setString(2, municipio);

So, the character problem is happening ONLY if I use setString. Any ideas?

EDIT: The value of the 'municipio' variable is, for example: 'ABADIÑO'. Later, I can check the differences between doing it on way or the other by asking for that value with an sql statement, for example:

select * from long_codes_table 
where table_name = 'MUNICIPIOS' and code__c = 'ABADIÑO'

One way I get the result row. The other way, I don't.

Thank you.


I had that behaviour, too. On top of that I observed that this error did not occur when the application was started from the IDE. That's how I realized that in the JVM - attributes, the one for the encoding was missing.

java %vm-opts% %clspth% -Dfile.encoding=UTF-8 ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜