java jdbc 字符串 sql server 字符编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7008756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jdbc string sql server character encoding
提问by david99world
If I have a jdbc string such as...
如果我有一个 jdbc 字符串,例如...
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
How do you say "connect with character encoding as utf-8 like you can if you were connecting with mysql?
你怎么说“使用 utf-8 字符编码连接,就像你连接 mysql 一样?
Thanks,
谢谢,
采纳答案by Tim Jansen
According to the documentation, there is no such propertyin the URL schema. But you probably don't need it anyway. The JDBC driver will take your strings in Java Unicode and return all values in Java Unicode. In Java it does not matter which character encoding the driver uses for communication with the DB (unless you do something really unusual, like trying to work around database bugs, or your database is not aware of the encoding of its content).
根据该文件,有没有这样的属性在URL模式。但无论如何你可能不需要它。JDBC 驱动程序将采用 Java Unicode 格式获取您的字符串,并以 Java Unicode 格式返回所有值。在 Java 中,驱动程序使用哪种字符编码与 DB 通信并不重要(除非您做了一些非常不寻常的事情,例如尝试解决数据库错误,或者您的数据库不知道其内容的编码)。
回答by Snicolas
Did you try, as in Php,
你有没有尝试过,就像在 PHP 中一样,
jdbc:sqlserver://serverName\instanceName;CharacterSet=UTF-8
Regards, stéphane
问候, 斯蒂芬