如何从结果数据库中显示汉字
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.268.0.154:1521:dbbd","ASCD","knj76yt");
Statement st=con.createStatement();
System.out.println("connection established successfully...!!");
ResultSet rs=st.executeQuery("Select * from users WHERE ROWNUM <51");
pw.println("<table border=1>");
while(rs.next())
{
String numbr= rs.getString(1);
String nm_eng= rs.getString(2);
String nm_chinese= new String(rs.getString(3).getBytes("iso-8859-1"),"UTF-8");
pw.println("<tr><td>"+numbr+"</td><td>"+nm_eng+"</td>"+
"<td>"+nm_chinese+"</td></tr>");
System.out.println(nm_chinese);
}
pw.println("</table>");
pw.close();
}
catch (Exception e){
System.out.println(e);
}
答案 0 :(得分:1)
您可以尝试类似的方法来显示中文输出,
OutputStream outputStream = System.out;
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-8");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
String chineseFromCode = nm_chinese;
bufferedWriter.write(chineseFromCode);
bufferedWriter.flush();