bboss persistent 实现数据库更新操作

简介: 4.5 更新操作代码段    4.5.1预编译更新操作        PreparedDBUtil preDBUtil = new PreparedDBUtil();        int pk = 0;        String sqlstr = "update OFFICE_...

4.5 更新操作代码段
   

4.5.1预编译更新操作
        PreparedDBUtil preDBUtil = new PreparedDBUtil();

       int pk = 0;

       String sqlstr = "update OFFICE_DOCINFO set DOCID=?, GETDOCID=?, " +

       "DOCDATE=?, RECIVEDATE=?, DOCTITLE=?, DOCUNIT=?, DOCURGENT=?, DOCKIND=?, " +

       "DOCCLASS=?, SECRET=?, DOCSUBJECT=?, DOCTYPE=?, DOCNUM=?, DOCOFFICE=?, " +

       "DOCINFO=?, DOCRESULT=?, DOCTRANSACT=?, DOCREMARK=?, DOCMODE=?, WORKLEVEL=?, " +

       "RESERVETERM=?, IDENTITY=?, DOCSUM=?, OLD_NUMBER=?, DOCKIND_ID=?, PROCESSID=?, " +

       "DOCTYPE_ID=?, CLASSID=?,isSend=? where DOCINFO_ID=?";

      

       DocInfo docInfo = (DocInfo)vo;

 

       String sDocId = docInfo.getDocId();

       String sGetDocId = docInfo.getGetDocID();

       Timestamp tsDocDate = (Timestamp) docInfo.getDocDate();

       Timestamp tsReceiveDate = (Timestamp) docInfo.getReciveDate();

       String sDocTitle = docInfo.getDocTitle();

       String sDocUnit = docInfo.getDocUnit();

       int    iDocUrgent = docInfo.getDocUrgent();

       String sDocClass = docInfo.getDocClass();

       String sDocKind = docInfo.getDocKind();

       String sSecret = docInfo.getSecret();

       String sDocSubject = docInfo.getDocSubject();

       String sDocType = docInfo.getDocType();

       String sDocNum = docInfo.getDocNum();

       String sDocOffice = docInfo.getDocOffice();

       String sDocInfo = docInfo.getDocInfo();

       String sDocResult = docInfo.getDocResult();

       String sDocTransact = docInfo.getDocTransact();

       String sDocRemark = docInfo.getDocRemark();

       int    iDocMode = docInfo.getDocMode();

       String sWorkLevel = docInfo.getWorkLevel();

       String sReserveTerm = docInfo.getReserveTerm();

       int    iIdentity = docInfo.getIdentity();

       String   iDocSum = docInfo.getDocSum();

       String sOld_number = docInfo.getOld_number();

       int    iDocKindId = docInfo.getDocKindId();

       //int     iProcessId = docInfo.getProcessId();

       String sProcessId = docInfo.getProcessId();

       int    iDocTypeId = docInfo.getDocTypeId();

       int    iDocClassId = docInfo.getDocClassId();

       int isSend = docInfo.getIsSend();

      

           try {

              preDBUtil.preparedUpdate(sqlstr); //在缺省的数据库上操作

                 //preDBUtil.preparedUpdate(“bspf”,sqlstr);在指定的数据库中,执行sql语句。

              preDBUtil.setString(1,sDocId);

              preDBUtil.setString(2,sGetDocId);

              preDBUtil.setTimestamp(3,tsDocDate);

              preDBUtil.setTimestamp(4,tsReceiveDate);

              preDBUtil.setString(5,sDocTitle);

              preDBUtil.setString(6,sDocUnit);

              preDBUtil.setInt(7,iDocUrgent);

              preDBUtil.setString(8,sDocClass);

              preDBUtil.setString(9,sDocKind);

              preDBUtil.setString(10,sSecret);

              preDBUtil.setString(11,sDocSubject);

              preDBUtil.setString(12,sDocType);

              preDBUtil.setString(13,sDocNum);

              preDBUtil.setString(14,sDocOffice);

              preDBUtil.setString(15,sDocInfo);

              preDBUtil.setString(16,sDocResult);

              preDBUtil.setString(17,sDocTransact);

              preDBUtil.setString(18,sDocRemark);

              preDBUtil.setInt(19,iDocMode);

              preDBUtil.setString(20,sWorkLevel);

              preDBUtil.setString(21,sReserveTerm);

              preDBUtil.setInt(22,iIdentity);

              preDBUtil.setString(23,iDocSum);

              preDBUtil.setString(24,sOld_number);

              preDBUtil.setInt(25,iDocKindId);

              preDBUtil.setString(26,sProcessId);

              preDBUtil.setInt(27,iDocTypeId);

              preDBUtil.setInt(28,iDocClassId);

              preDBUtil.setInt(29,isSend);

              preDBUtil.setInt(30,docInfo.getDocInfoId());

             

              Object obj = preDBUtil.executePrepared();

              return docInfo.getDocInfoId();

           } catch (SQLException e) {

              e.printStackTrace();

              throw new DataAccessException("向OFFICE_DOCINFO表插入记录错:"+e.getMessage(),e);

           }

    

4.5.2一般更新操作
       

        String sqlstr = "UPDATE OFFICE_DOCINFO SET DOCMODE = " + newStatus +" WHERE DOCINFO_ID = "+docInfoId;

       DBUtil dbUtil = new DBUtil();

       try {

           dbUtil.executeUpdate(sqlstr);

// dbUtil.executeUpdate(“bspf”,sqlstr);;在指定的数据库中,执行sql语句。

 

       } catch (SQLException e) {

           e.printStackTrace();

           throw new DataAccessException("更新公文状态错:"+e.getMessage(),e);

       }

      

 

 

 

4.5.3 CLOB字段的更新操作
PreparedDBUtil db = new PreparedDBUtil();

       StringBuffer sql = new StringBuffer();

       sql.append("update TD_CMS_DOCUMENT set TITLE=?,SUBTITLE=?,")     

           .append("AUTHOR=?,CONTENT=?,KEYWORDS=?,")      //dockind

           .append("DOCABSTRACT=?,")

           .append("TITLECOLOR=?,")

           .append("DOCSOURCE_ID=?,")

           .append("DETAILTEMPLATE_ID=?,")

           .append("LINKTARGET=?,Doc_level=?,PARENT_DETAIL_TPL=?,PIC_PATH=?,mediapath=?,publishfilename=?,")

           .append("docwtime=" + DBUtil.getDBDate(doc.getDocwtime()))

           .append(",secondtitle=?,isnew=?,newpic_path=?,ordertime=? where document_id=?") ;

 

      

       try

       {

           db.preparedUpdate(sql.toString());

           //db.preparedUpdate(“bspf”,sql.toString());

          

           db.setString     (1,doc.getTitle());

           db.setString     (2,doc.getSubtitle());

           db.setString     (3,doc.getAuthor());

           db.setClob       (4,doc.getContent(),"content");

           db.setString     (5,doc.getKeywords());

           db.setString     (6,doc.getDocabstract()==null?"无":doc.getDocabstract());

           db.setString     (7,doc.getTitlecolor());

           db.setInt        (8,doc.getDocsource_id());

           db.setInt        (9,doc.getDetailtemplate_id());

           db.setString     (10,doc.getLinktarget());

           db.setInt        (11,doc.getDoc_level());

           db.setString     (12,doc.getParentDetailTpl());

           db.setString     (13,doc.getPicPath());

           db.setString     (14,doc.getMediapath());

           db.setString     (15,doc.getPublishfilename());

           db.setString     (16,doc.getSecondtitle());

           db.setInt        (17,doc.getIsNew());

           db.setString     (18,doc.getNewPicPath());

           db.setTimestamp  (19,new Timestamp(doc.getOrdertime().getTime()));

           db.setPrimaryKey (20,doc.getDocument_id());

           db.executePrepared();

          

           b = true;

       }

       catch (SQLException e)

       {

           e.printStackTrace();

           throw new DocumentManagerException(e.getMessage());

       }

       return b;

 

4.5.3 BLOB字段的更新操作
PreparedDBUtil db = new PreparedDBUtil();

       StringBuffer sql = new StringBuffer();

       sql.append("update TD_CMS_DOCUMENT set TITLE=?,SUBTITLE=?,")     

           .append("AUTHOR=?,CONTENT=?,KEYWORDS=?,")      //dockind

           .append("DOCABSTRACT=?,")

           .append("TITLECOLOR=?,")

           .append("DOCSOURCE_ID=?,")

           .append("DETAILTEMPLATE_ID=?,")

           .append("LINKTARGET=?,Doc_level=?,PARENT_DETAIL_TPL=?,PIC_PATH=?,mediapath=?,publishfilename=?,")

           .append("docwtime=" + DBUtil.getDBDate(doc.getDocwtime()))

           .append(",secondtitle=?,isnew=?,newpic_path=?,ordertime=? where document_id=?") ;

 

      

       try

       {

           db.preparedUpdate(sql.toString());

           //db.preparedUpdate(“bspf”,sql.toString());

          

           db.setString     (1,doc.getTitle());

           db.setString     (2,doc.getSubtitle());

           db.setString     (3,doc.getAuthor());

           db.setBlob       (4,doc.getContent(),"content");

           db.setString     (5,doc.getKeywords());

           db.setString     (6,doc.getDocabstract()==null?"无":doc.getDocabstract());

           db.setString     (7,doc.getTitlecolor());

           db.setInt        (8,doc.getDocsource_id());

           db.setInt        (9,doc.getDetailtemplate_id());

           db.setString     (10,doc.getLinktarget());

           db.setInt        (11,doc.getDoc_level());

           db.setString     (12,doc.getParentDetailTpl());

           db.setString     (13,doc.getPicPath());

           db.setString     (14,doc.getMediapath());

           db.setString     (15,doc.getPublishfilename());

           db.setString     (16,doc.getSecondtitle());

           db.setInt        (17,doc.getIsNew());

           db.setString     (18,doc.getNewPicPath());

           db.setTimestamp  (19,new Timestamp(doc.getOrdertime().getTime()));

           db.setPrimaryKey (20,doc.getDocument_id());

           db.executePrepared();

          

           b = true;

       }

       catch (SQLException e)

       {

           e.printStackTrace();

           throw new DocumentManagerException(e.getMessage());

       }

  4.5.4 预编译更新操作和普通更新操作的不同点


jdbc规范提供了两种不同的更新操作模式:预编译和普通两种,二者的区别为:

预编译更新的操作效率高,有效防止sql注入问题,编码和调试没有普通更新操作方便,综合各种因素推荐使用预编译更新操作。

 

目录
打赏
0
0
0
0
5
分享
相关文章
【SSH快速进阶】——探索Hibernate对象的三种状态:Transient、Persistent、Detached
 学习过操作系统的朋友,脑子里肯定都会有这张进程的状态转换图:
【SSH快速进阶】——探索Hibernate对象的三种状态:Transient、Persistent、Detached
hibernate persist update 方法没有正常工作(不保存数据,不更新数据)
工程结构 问题描述 在工程中通过spring aop的方式配置事务,使用hibernate做持久化。在代码实现中使用hibernate persit()方法插入数据到数据库,使用hibernate update()方法更新数据。
1179 0
Hibernate save, saveOrUpdate, persist, merge, update 区别
Hibernate Save hibernate save()方法能够保存实体到数据库,正如方法名称save这个单词所表明的意思。我们能够在事务之外调用这个方法,这也是我不喜欢使用这个方法保存数据的原因。
1370 0
bboss-persistent结合bboss-aop实现注解事务
bboss-persistent结合bboss-aop也可以实现注解事务哦. 先看一个业务组件: package org.frameworkset.spi.transaction.annotation; import java.
636 0
bboss persistent 实现数据库删除操作
4.6 删除操作4.6.1    普通删除操作    DBUtil dbUtil = new DBUtil();               try {            dbUtil.
621 0
使用bboss persistent框架实现数据库的插入操作
4.3.1预编译插入        PreparedDBUtil preDBUtil = new PreparedDBUtil(); ----------------->定义预编组件实例        Action action = (Action)vo;        String sRecord = action.
756 0
关于bboss persistent主键生成机制的说明
4.14 主键的生成 bboss主键生成有两种模式,一种模式是在对象主键属性上加@PrimaryKey(uuid主键)或者@PrimaryKey(auto=true,pkname="xxxx")(pkname对应tableinfo中的TABLE_NAME子字段的值),另外一种模式就是通过DBUtil.getNextPrimaryKey方法再程序中获取(前提是表的主键信息需要配置到tableinfo中,可以支持uuid和oracle的sequence,以及mysql的自定义sequence)。
1053 0
获取数据库连接-bboss persistent
  bboss persistent下载地址 https://sourceforge.net/project/showfiles.php?group_id=238653&package_id=302766&release_id=647144 获取数据库连接-bboss persistentbboss persistent获取数据链接的两种方式1.
770 0
bboss persistent事务管理介绍 (一)
bboss项目下载列表 在sourceforge访问地址为:https://sourceforge.net/project/showfiles.php?group_id=238653 bboss persistent的事务管理框架实现数据库的增、删、改、查事务管理,整个事务管理框架在下面的各节中详细介绍。
754 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等