Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

java - Reading Unicode characters from an Access database via JDBC-ODBC

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...