//byte[] buf = new byte[2048]; 这个时候可以插入.txt文件,但插入不进去图片不知道为什么
byte[] buf = new byte[204800]; //这个时候去可以插入图片,原因不知道为啥
int len = 0;
if((len = bis.read(buf,0,buf.length)) != -1) { //如果为bis.read()没有参数的话,.txt,.jpg等都插入不进去,不知道为什么
os.write(buf, 0, len);
os.flush();
}
bis.read(buf,0,buf.length)就是说我要读取上面定义的那个buf个字节是吗?而且是只读取这些????
如果向数据库中插入图片,最好采用PreparedStatement进行,不知道你这里的os是写到那里去了
Product item = Product();
java.sql.Blob picture = item.getPicture();
InputStream in = picture.getBinaryStream();
byte[] b = new byte[512];
int len = in.read(b);
while(len != -1){
out.write(b, 0, len);
len = in.read(b);
}
//试一下