(다른 특수 문자가 성공적으로하지만,이 경우는 아직 분석되지 않은 반환 될 수 있습니다)와 같은 특수 문자를 얻을 수있는 방법 :
모든 반환 된 문자열을 올바르게 (즉, 쿼리 된 필드를 의미하는) 다음 절차를 따라야합니다. 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