多数据源开发
- 创建数据源,点击创建数据源,添加数据源参数,保存,然后测试,看是否成功。
- 连接数据源的方法,代码如下
weaver.interfaces.datasource.DataSource ds = (weaver.interfaces.datasource.DataSource) StaticObj.getServiceByFullname((“datasource.GSRM”), weaver.interfaces.datasource.DataSource.class);
java.sql.Connection conn = ds.getConnection(); |
- 代码操作,采购jdbc方式连接,直接操作本地数据库
public String test(String requestId,String lastname){
weaver.interfaces.datasource.DataSource ds = (weaver.interfaces.datasource.DataSource) StaticObj.getServiceByFullname((“datasource.GSRM”), weaver.interfaces.datasource.DataSource.class); java.sql.Connection conn = ds.getConnection(); PreparedStatement ps=null; //创建结果集 if (null == conn) { writeLog(“连接为空。”); } else { writeLog(“已经连接。”); }
//为采购申请主表修改状态 try { String sql0 =”update gsrm_porequest_entry set STATUS_POREQUEST=’2′ where request_id='”+requestId+”‘”; ps = conn.prepareStatement(sql0); int count = ps.executeUpdate(); writeLog(“============修改条数1:” + String.valueOf(count)); } catch (SQLException e) { e.printStackTrace(); } //采购申请从表修改状态 try { String sql =”update gsrm_porequest set BPM_STATUS=’3′ where request_id='”+requestId+”‘”; ps = conn.prepareStatement(sql); int count = ps.executeUpdate(); writeLog(“============修改条数2:” + String.valueOf(count)); } catch (Exception e) { e.printStackTrace(); }
// try { String sql1 =”update GSRM_POREQUEST_ENTRY set POREQ_ENTRY_BUYER='”+lastname+”‘ where id in( select id from GSRM_POREQUEST_ENTRY where POREQ_ENTRY_FINTERID in(select POREQ_FINTERID from gsrm_porequest where request_id='”+requestId+”‘ ))”; ps = conn.prepareStatement(sql1); int count = ps.executeUpdate(); writeLog(“============修改条数3:” + String.valueOf(count)); } catch (Exception e) { e.printStackTrace(); } try { ps.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } return “1”; } |
转载请注明:赫非域 » Ecology OA多数据源开发