问题描述
信息:schemaupdatecompleteHibernate:insertintoFileEntity(mybyte,name)values(?,?)2013-11-1323:27:10org.hibernate.util.JDBCExceptionReporterlogExceptions警告:SQLError:8152,SQLState:220012013-11-1323:27:10org.hibernate.util.JDBCExceptionReporterlogExceptions严重:将截断字符串或二进制数据。我想将文件用二进制的形式存在数据库中,实体类中字段写的是:byte[]mybyte;求给位帮帮忙~
解决方案
解决方案二:
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{FileUpDownToolupDownTool=newFileUpDownTool();List<Object>list;try{list=upDownTool.sortData(request);Map<String,String>hms=(Map<String,String>)list.get(0);Map<String,InputStream>hmb=(Map<String,InputStream>)list.get(1);DAOFiledaofile=newDAOFile();FileEntitymyfile=newFileEntity();//实体类Stringname=hms.get("username");myfile.setName(name);StringfileName=hms.get("picFile");if(hmb.containsKey(fileName)){InputStreamis=hmb.get(fileName);byte[]bytePic=newbyte[is.available()];@SuppressWarnings("unused")inti=is.read(bytePic);myfile.setMybyte(bytePic);}daofile.addBusiness(myfile);}catch(FileUploadExceptione){e.printStackTrace();}}
解决方案三:
数据库相关字段用的是BLOB吗?