2014-03-26 7 views
1

MS Access 데이터베이스 용 jdbc-odbc 드라이버를 사용하여 Ms 액세스 (.accdb 또는 .mdb) 데이터베이스에서 특수 문자를 반환하는 방법은 무엇입니까? (다음 bytes[] bt = rs.getbytes(index_of_field)new String (bt, "UTF-8") 또는 new String (bt, "iso-8859-1")) 결과 집합의 바이트 문자열 (rs.getString())가 작동하지 않습니다 당신이 그것을 할 수있는 유효한 방법이 필요 얻기에서 변환jdbc-odbc 드라이버를 사용하여 MS Access db에서 특수 스페인어 문자를 올바르게 반환하는 방법

.

답변

2

(다른 특수 문자가 성공적으로하지만,이 경우는 아직 분석되지 않은 반환 될 수 있습니다)와 같은 특수 문자를 얻을 수있는 방법 :

  • A, E, I, O를 Ú을,

모든 반환 된 문자열을 올바르게 (즉, 쿼리 된 필드를 의미하는) 다음 절차를 따라야합니다. DB를에 연결하기 전에

는 donde, 그리고 데이터베이스를 조회하기 전에, 우리는 캐릭터 세트 같은 속성 매개 변수를 정의해야합니다

Properties props; 

props = new Properties(); 
props.put ("charSet", "iso-8859-1"); 

그런 다음 우리는 데이터베이스 연결에 소품을 추가해야합니다. 결국 이것은 필요한 최종 코드입니다. 한 번만 rs.getString()을 실행할 수 있기 때문에

String dbPath = "C:/example/directory/myDatabase.accdb"; 


Properties props; 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
String connURL="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+dbPath; 

try { 

    props = new Properties(); 
    props.put ("charSet", "iso-8859-1"); 

    con = DriverManager.getConnection(connURL, props); 
    stmt = con.createStatement(); 
    stmt.execute("select "field+" from "+tableName); // query exec 

    rs = stmt.getResultSet(); // query resultset 
    rsMetaData = rs.getMetaData(); // resultset metadata 

} catch (SQLException ex) { 

    return false; 
} 

은 그럼 그냥, 경우에 당신이 한 번 이상 더를 사용하려면, (AN 보조 변수에 문자열을 저장하는 기억 문자열로 각 필드의 값을 반환해야) :

String resultString; 

if(rs != null){ 

    while(rs.next()){ // this while may be surrounded with a try-catch 
    // Fields will be displayed for every row in the DB 
    // indexField must start from 1 ! 

    for (int indexField = 1; indexField<=rsMetaData.getColumnCount(); indexField++){ 

     resultString = rs.getString(field_index); 
     System.out.println(This is the field of column number "+indexField+": "+resultString); 

    } // for close 
    } // while close 
} // if close