开发者

Retrieving MS Access column with international name from Java (encoding)

开发者 https://www.devze.com 2023-03-16 02:07 出处:网络
I need to import data from some legacy Access databases. I ran the code with some database file, and everything went fine. Now, I tried it with another one and the same code doesn\'t work.

I need to import data from some legacy Access databases. I ran the code with some database file, and everything went fine. Now, I tried it with another one and the same code doesn't work.

It seems to be related to character encoding, although I didn't specify anything (and wouldn't know where to do that).

Double age = resultSet.getDouble("âge");

works on first db file, gives an SQLException with "Column not found" on another one. On the problematic database, resultSet.getMetaData().getColumnName(3) (same column) gives "?ge".

UPDATE: it seems that the result is in fact consistent between databases开发者_C百科. The difference I saw was because the first import was run from a class in an EJB-project (I ran the main method of some class, not the EJB module in an app server). The second import was done on a new standalone project. The standalone Java project always fails with this exception, but running the same code in the first project always works.

question formulated another way here: https://stackoverflow.com/questions/6519517/getting-ms-access-column-with-international-character-from-java


Manipulating an Access database via the JDBC-ODBC Bridge and the Access ODBC driver will only work reliably for accented characters that are included in the Windows-1252 character set. In those cases you must set the character encoding of the Java source file to cp1252 in Eclipse (or set the character encoding of the project to windows-1252 in NetBeans). If your Java source file is encoded as UTF-8 then your code will NOT work if accented characters are involved. (For more details see my other answer here.)

For more complete Unicode character support consider using UCanAccess instead.

0

精彩评论

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