读取mysql中的Blob字段
if(meta.getColumnClassName(i).contains("[B")){ InputStream in = rs.getBinaryStream(i); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[4096]; int count = -1; while((count = in.read(data,0,4096)) != -1) outStream.write(data, 0, count); data = null; value = new String(outStream.toByteArray(),"gbk"); Method method=obj.getClass().getMethod(methodName, Class.forName("java.lang.String")); method.invoke(obj, value); in.close(); outStream.close(); }else{ Method method=obj.getClass().getMethod(methodName, Class.forName(meta.getColumnClassName(i))); method.invoke(obj, value); }
Blob读取出来的类型是[B,java中没有这个类型,用反射时需要自己转换来读取。
本文固定链接:http://www.yizhi227.com/?post=78
本文由Jessie原创或编辑,互联分享,尊重版权,转载请以链接形式标明本文地址
本文由Jessie原创或编辑,互联分享,尊重版权,转载请以链接形式标明本文地址