问题描述
我有一个book对象,代码如下;packagecom.bookshow.business.bookmgr.model;importjava.io.InputStream;importjava.util.Date;publicclassBook{privateStringbookId;privateStringcatId;privateStringbookName;privateStringauthor;privateStringprice;privateStringdescription;privateStringcontent;privateInputStreambookImage;privateDatecreateDate;publicStringgetBookId(){returnbookId;}publicvoidsetBookId(StringbookId){this.bookId=bookId;}publicStringgetCatId(){returncatId;}publicvoidsetCatId(StringcatId){this.catId=catId;}publicStringgetBookName(){returnbookName;}publicvoidsetBookName(StringbookName){this.bookName=bookName;}publicStringgetPrice(){returnprice;}publicvoidsetPrice(Stringprice){this.price=price;}publicStringgetDescription(){returndescription;}publicvoidsetDescription(Stringdescription){this.description=description;}publicStringgetContent(){returncontent;}publicvoidsetContent(Stringcontent){this.content=content;}publicDategetCreateDate(){returncreateDate;}publicvoidsetCreateDate(DatecreateDate){this.createDate=createDate;}publicStringgetAuthor(){returnauthor;}publicvoidsetAuthor(Stringauthor){this.author=author;}publicvoidsetBookImage(InputStreambookImage){this.bookImage=bookImage;}publicInputStreamgetBookImage(){returnbookImage;}}还有一个BookActionForm:packagecom.bookshow.web.bookmgr.forms;importorg.apache.struts.action.ActionForm;importorg.apache.struts.upload.FormFile;publicclassBookActionFormextendsActionForm{privateStringbookId;privateStringcatId;privateStringbookName;privateStringprice;privateStringdescription;privateStringcontent;privateFormFilebookImage;privateString[]selectFlag;publicString[]getSelectFlag(){returnselectFlag;}publicvoidsetSelectFlag(String[]selectFlag){this.selectFlag=selectFlag;}publicStringgetBookId(){returnbookId;}publicvoidsetBookId(StringbookId){this.bookId=bookId;}publicStringgetCatId(){returncatId;}publicvoidsetCatId(StringcatId){this.catId=catId;}publicStringgetBookName(){returnbookName;}publicvoidsetBookName(StringbookName){this.bookName=bookName;}publicStringgetPrice(){returnprice;}publicvoidsetPrice(Stringprice){this.price=price;}publicStringgetDescription(){returndescription;}publicvoidsetDescription(Stringdescription){this.description=description;}publicStringgetContent(){returncontent;}publicvoidsetContent(Stringcontent){this.content=content;}publicFormFilegetBookImage(){returnbookImage;}publicvoidsetBookImage(FormFilebookImage){this.bookImage=bookImage;}}我的BookDaoMySQLImpl里面有一个addBook()方法:publicvoidaddBook(Connectionconn,Bookbook){Stringsql="insertintobook_table(bookId,catId,bookName,author,price,description,content,bookImage,createDate)"+"values(?,?,?,?,?,?,?,?)";PreparedStatementpstmt=null;try{pstmt=conn.prepareStatement(sql);pstmt.setString(1,book.getBookId());pstmt.setString(2,book.getCatId());pstmt.setString(3,book.getBookName());pstmt.setString(4,book.getAuthor());pstmt.setString(5,book.getPrice());pstmt.setString(6,book.getDescription());pstmt.setString(7,book.getContent());pstmt.setBinaryStream(8,book.getBookImage());pstmt.setTimestamp(9,newTimestamp(book.getCreateDate().getTime()));pstmt.executeUpdate();conn.commit();pstmt.close();}catch(SQLExceptione){e.printStackTrace();}finally{DB.closeConn(conn);}}我在AddBookAction里面这样写:packagecom.bookshow.web.bookmgr.actions;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.apache.commons.beanutils.BeanUtils;importorg.apache.struts.action.Action;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;importorg.apache.struts.upload.FormFile;importcom.bookshow.business.bookmgr.manager.BookManager;importcom.bookshow.business.bookmgr.model.Book;importcom.bookshow.web.bookmgr.forms.BookActionForm;publicclassAddBookActionextendsAction{@OverridepublicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse)throwsException{BookActionFormbaf=(BookActionForm)form;try{FormFilebookImage=baf.getBookImage();bookImage.getInputStream();System.out.println(bookImage.getInputStream());Bookbook=newBook();BeanUtils.copyProperties(book,baf);BookManager.getInstance().addBook(book);}catch(Exceptione){e.printStackTrace();}finally{}returnmapping.findForward("success");}}那给高手给我看看,我第一次来这里问问题。实在是急啊~~~~~~~谢谢~~~~~~~~~~我没有多少分,就给10分吧。
解决方案
解决方案二:
把bookImage类型设置成String的数据库里保存的应该是图片路径你那样做的话你想数据库里会放多少二进制的代码?
解决方案三:
有什么错误提示?靠,程序没看到问题呀,不过你用mysql,哈,在connectionurl里面characterEncoding不可以是gbk。要不然,就出问题了。
解决方案四:
另外数据库image字段的类型是blob
解决方案五:
我设为gbk待该会出什么样的问题提呢???
解决方案六:
有一个类型不匹配的提示~~~~~~~
解决方案七:
继续求助,我不知道在Book里面的图片的属性要设置成为什么?在dao中如何操作这个图片。
解决方案八:
想保存什么,图片格式/还是字符串,应该没有问题的!
解决方案九:
还是没有解决。