源自:3-4 [Hibernate单表操作] 对象类型
MySQL存图片报错
请教@Test
public void testWriteBlob() throws IOException{
Students s=new Students(1,"韩菱纱", "女", new Date(), "仙剑");
//先获取照片文件 File.separator为文件9分隔符
File f=new File("d:"+File.separator+"xmm.jpg");
//获得照片文件的输入流
InputStream input=new FileInputStream(f);
//创建一个Blod对象createBlob(arg1,arg2);第一个参数为从哪个输入流读取第二个参数为读取的长度
//长度应该为此输入流的可用长度即input.available()
Blob image=Hibernate.getLobCreator(session).createBlob(input, input.available());
//设置照片属性
s.setPicture(image);
//保存学生
session.save(s);
}
报的错误是:ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\0\0\0\0\0萛0\0怽0\0\0\0\00221?\0\0\0\0\0\0P?\0\0\0\0\0\0d?\0\0\0\0' at line 1
这种错误搜都不好搜……
提问者:勇往直前灬
2016-06-27 20:19