jsp/java读取mysql的blob类型字段中文乱码问题? 代码如下,但是出来的是乱码? 10
Stringstr="";//StringBuildersb=newStringBuilder();intlen=0;while((len=in.read(b))!=-1...
String str = "";
//StringBuilder sb = new StringBuilder();
int len = 0;
while ((len = in.read(b)) != -1) {
str += new String(b, 0, len);
//sb.append((char) len);
}
每个blob类型长度为200字节,存储了100个数,为何这样提取出来是乱码?该如何做?
private static void readDB() {
try {
Connection conn = Test.getConnection();
String sql = "select * from dfi_data";
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
InputStream in = rs.getBlob("data_blob").getBinaryStream();
byte[] b = new byte[1024];
String str="";
int len = 0;
while((len=in.read(b))!=-1){
str += new String(b,0,len);
}
System.out.println(str);
//System.out.println(Arrays.toString(str.getBytes()));
in.close();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
readDB();
} 展开
//StringBuilder sb = new StringBuilder();
int len = 0;
while ((len = in.read(b)) != -1) {
str += new String(b, 0, len);
//sb.append((char) len);
}
每个blob类型长度为200字节,存储了100个数,为何这样提取出来是乱码?该如何做?
private static void readDB() {
try {
Connection conn = Test.getConnection();
String sql = "select * from dfi_data";
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
InputStream in = rs.getBlob("data_blob").getBinaryStream();
byte[] b = new byte[1024];
String str="";
int len = 0;
while((len=in.read(b))!=-1){
str += new String(b,0,len);
}
System.out.println(str);
//System.out.println(Arrays.toString(str.getBytes()));
in.close();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
readDB();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询