81,091
社区成员
发帖
与我相关
我的任务
分享
"engine=odbc;odbcapi=ansi;charset=utf8;DSN=mysource"
这种写法可能是 M$ 编程中的 OLEDB 之类的,反正不是 Java。
byte[] bytes = // 从 socket 或文件中读取。
String field = new String(bytes); // 这句相当于 new String(bytes, System.getProperty("file.encoding"));
// 如果原来它是 UTF8 或其它编码方式编码的 byte [],那这个时候就是乱码。
// 所以我们需要给驱动程序说明它应该使用某个字符集而不使用操作系统默认的。
这个文章
How driver manager converts between Unicode and ANSI
中提到:
The only "working" solution i could figure out is to implement both
wide and ansi APIs and the user must specify which one internally
should be used and for the anis API, a character set must be specified.
For example the configuration string for my library could be
something like
"engine=odbc;odbcapi=ansi;charset=utf8;DSN=mysource"
or
"engine=odbc;odbcapi=unicode;DSN=mysource"
So if the user really needs to load a odbc 2.0 driver which only
returns iso-850 chars, he can configure my lib this way (extreme
example).
I don't see any other chance to provide working odbc support.
但还是不知道怎么在写 JDBC 连接的 URL 中这样指定参数,它这个 ODBC 连接串不像是 JDBC 能识别的(?我也不确定,常见的 JDBC-ODBC URL 不是这么写的啊)