通过 JDBC-ODBC 从 Access 数据库中读取 Unicode 字符 [英] Reading Unicode characters from an Access database via JDBC-ODBC
本文介绍了通过 JDBC-ODBC 从 Access 数据库中读取 Unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 Access 2010 数据库中有一些非标准字符.当我通过
I have some non-standard characters in my Access 2010 database. When I read them via
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.util.Properties prop = new java.util.Properties();
prop.put("charSet", "UTF8");
String database = "jdbc:odbc:Lb";
con = DriverManager.getConnection(database, prop);
} catch (Exception ex) {
System.out.println("Error");
}
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("SELECT distinct forename, surname from PSN where isValid");
while (rs.next()) {
String forename = rs.getString("forename");
}
我在字符应该出现的位置收到问号 (?
).这是为什么?
I receive question marks (?
) where the character should be. Why is this?
推荐答案
当 DB 包含波兰语字符时,我有问号.当我将字符编码设置为 windows-1250 时已修复.
I had question marks when DB contained polish characters. It was fixed when I set charecter encoding to windows-1250.
def establish(dbFile: File): Connection = {
val fileName = dbFile.getAbsolutePath
val database = s"${driver}DBQ=${fileName.trim};DriverID=22;READONLY=true}"
val props = new Properties()
props.put("charSet", "Cp1250")
val connection= DriverManager.getConnection(database,props)
connection
}
这篇关于通过 JDBC-ODBC 从 Access 数据库中读取 Unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文