3

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. 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

5
  • 1
    I would advise you to use resultSet.getDouble(int) to avoid future errors as well. Jun 28, 2011 at 12:08
  • column order isn't guaranteed
    – ymajoros
    Jun 28, 2011 at 12:26
  • 1
    You might be using the iso-8859-1 charset in your database, well you will have to convert the string âge to age using charset converters before getting the data in that column. Another workaround is to change the charset of the database to utf8 or utf16
    – Rakesh
    Jun 30, 2011 at 9:31
  • @Rakesh: I don't know how access encodes databases internally. For decent databases, it's jdbc responsability (sometimes with configuration) to give a translated java string to the applications, so accents should appear and be decoded correctly. The strange thing is, as I said, I copy/pasted the code from one project to another one. It works (no error using "âge") in project 1 but not in 2.
    – ymajoros
    Jul 1, 2011 at 14:47
  • Check the charset of the java source file. Are you using Eclipse? If yes you can compare both project source files using context-menu Properties option.
    – Zecas
    May 28, 2012 at 16:12

1 Answer 1

0

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.

1
  • They do exist in both charsets, that's not the problem.
    – ymajoros
    Feb 24, 2014 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.