简体   繁体   English

在数据库上发现Java未知字符

[英]Java Unknown char found on database

I'm creating a program that connects java to access database but I found some problem after inserting some string in the table. 我正在创建一个将Java连接到数据库的程序,但是在表中插入一些字符串后发现了一些问题。

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. 我确定我的代码没有什么问题,我只是不知道为什么将未知字符插入数据库后为什么不存在。

The encoding used by Java and the encoding used by your database don't match up. Java使用的编码和数据库使用的编码不匹配。 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). 引用的SO文章(在上面的评论中)似乎是适当的,因为Java使用Unicode,而Access很可能不使用Unicode(它可能使用CP-1252或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 . 这是一个使用Java的CharsetEncoder做到这一点的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM