试试:
while{rs.next){
content=new String(rs.getString("content").getByte("iso-8859_1"),"GBK");//(或用"gb2312","utf-8","GBK")都没用
}
while{rs.next){
content=new String(rs.getString("content").getByte("iso-8859_1"),"GBK");//(或用"gb2312","utf-8","GBK")都没用
}
前提是确保插入数据库的是中文
import sun.io.*;public static String AsciiToChineseString(String s) {
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (byte)(orig[i]&0xFF);
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));
}
catch (Exception e) {
System.out.println(e);
return s;
}
} public static String ChineseStringToAscii(String s) {
try {
CharToByteConverter toByte = CharToByteConverter.getConverter"gb2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}
import sun.io.*;public static String AsciiToChineseString(String s) {
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (byte)(orig[i]&0xFF);
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));
}
catch (Exception e) {
System.out.println(e);
return s;
}
} public static String ChineseStringToAscii(String s) {
try {
CharToByteConverter toByte = CharToByteConverter.getConverter"gb2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}
import sun.io.*;public static String AsciiToChineseString(String s) {
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (byte)(orig[i]&0xFF);
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));
}
catch (Exception e) {
System.out.println(e);
return s;
}
} public static String ChineseStringToAscii(String s) {
try {
CharToByteConverter toByte = CharToByteConverter.getConverter"gb2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}