/**
*Java从数据库中读取图片并转化为字符串类型
*/
public String getUser(int account){
String msg1=null;JSONObject json=new JSONObject();
JSONArray jsonMembers = new JSONArray();
JSONObject json1=new JSONObject();
try {
String sql = "select * from yq_user where uaccount="+account;
Connection conn = DBUtil.getDBUtil().getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
InputStream in=null;
OutputStream out=null;
while(rs.next()){
in=rs.getBinaryStream("uimg"); //获取rs结果集中的每张图片
//申明byte数组,用来存放图片流 ,注意图片的大小
byte[] b=new byte[100000];
in.read(b); //从InputStream对象中读取数据放进byte数组中
String s = new String(b,"ISO-8859-1");//注意编码格式,转码格式错误,会导致图片乱码
json1.put("uaccount", rs.getInt("uaccount"));
json1.put("unick", rs.getString("unick"));
json1.put("uavatar",rs.getString("uavatar"));
json1.put("utrends", rs.getString("utrends"));
json1.put("usex",rs.getString("usex"));
json1.put("uage",rs.getInt("uage"));
json1.put("ulev",rs.getInt("ulev"));
json1.put("uimg",s);
jsonMembers.put(json1);
json.put("user", jsonMembers);
msg1=json.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return msg1;
}