我正在尝试使用 jdbc java 从 Oracle 表中获取一个 clob 字段并将其写入文件,但有些字符写错了。
public static void main(String[] args) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
InputStreamReader st = null;
Writer wr = null;
try {
conn = DataSource.getConnection("URL", "USER", "PASS");
ps = conn.prepareStatement("select fieldClob from tableTest");
rs = ps.executeQuery();
while(rs.next()) {
oracle.sql.CLOB clob = (CLOB)rs.getObject("fieldClob");
st = new InputStreamReader(clob.getAsciiStream(),Charset.forName("UTF-8"));
int intValueOfChar;
StringBuilder buffer = new StringBuilder();
while ((intValueOfChar = st.read()) != -1) {
buffer.append((char) intValueOfChar);
}
wr = new FileWriter("C:/test/file.xml");
wr.write(buffer.toString());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
CloseObject.closeObject(rs);
CloseObject.closeObject(ps);
CloseObject.closeObject(conn);
}
}
}
我想得到“ü”但我得到“[xBF]”或者我得到“?” 尝试 UTF-8 字符集。
一只名叫tom的猫
相关分类