2

I'm creating a program that connects java to access database but I found some problem after inserting some string in the table.

I found this character: Â on every record that has "-" on it.

Example Data:

 A Sample Input -Data

When I try to check the database, I found this:

A Sample Input Â-Data

I don't know where did I get that character.

Im sure there is nothing wrong with my code, I just don't know why there is unknown char after inserting it on database.

Cœur
  • 37,241
  • 25
  • 195
  • 267
nfinium
  • 141
  • 3
  • 8
  • 1
    Possibly related to http://stackoverflow.com/questions/1461907/html-encoding-issues-character-showing-up-instead-of-nbsp – n00begon Jun 07 '12 at 04:43

1 Answers1

1

The encoding used by Java and the encoding used by your database don't match up. The referenced SO article (in the comments above) seems appropriate, since Java uses Unicode and Access most likely does not (it probably uses CP-1252 or ISO-8859-1).

You haven't mentioned what library you're using to access the database. You should see if there's an option that allows you to specify the encoding. If not, then you may have to do the conversion yourself. Here's one example of how to do this using Java's CharsetEncoder.

jdigital
  • 11,926
  • 4
  • 34
  • 51
  • Yep, I also think that's the problem but I dont know how to fix it. I cant find any way to change the encoding to Unicode in MS Access settings – nfinium Jun 07 '12 at 05:45
  • Check the library you're using and see if it offers encoding support (in particular, check the method you use to connect to the database). If that doesn't help, then you'll need to do a manual conversion. – jdigital Jun 07 '12 at 17:36
  • *"Java uses Unicode and Access most likely does not (it probably uses CP-1252 or ISO-8859-1)"* - That was true for the earliest versions of Access, but Jet 4.0 added Unicode support so Access has supported Unicode since Access_2000 was released in 1999. – Gord Thompson Jul 29 '17 at 18:49