批量新增,table可多选操作
/**
* 批量新增操作
* @param actionEvent
*/
public void addDialogListener(ActionEvent actionEvent) {
try {
List<Row> selectRows = ADFUtils.getTableSelectedRows(richTable); //选中的多行专业数据
if (selectRows.size() == 0) {
Noty.error(ErrorStringKey.UNSELECTROW_TIPS);
return;
}
String njdm = (String)ADFUtils.getSelectListValueOne("XtglJxdmjNjdmView1","Dm"); //年级代码
String xqdm = (String)ADFUtils.getSelectListValueOne("XqjbsjzlLov1","Xqdm"); //校区代码
String dwdm = (String)ADFUtils.getBoundAttributeValue("Ssdw");//单位基本信息代码
String zyfxdms = "";
for (Row row : selectRows) {
String zyfxdm = (String)row.getAttribute("Zyfxdm");
zyfxdms += zyfxdm+",";
}
dmjServiceAMImpl am = (dmjServiceAMImpl)ADFUtils.findIterator("XtglNjzyxxbVO1Iterator").getViewObject().getApplicationModule();
String stmt = "BEGIN XTGL_NJZYXXB_ADD(?,?,?,?,?); END;";
java.sql.CallableStatement st = null;
try {
st = am.getDBTransaction().createCallableStatement(stmt, 0);
st.setString(1, zyfxdms); //传入参数
st.setString(2, njdm);
st.setString(3, xqdm);
st.setString(4, dwdm);
st.registerOutParameter(5, Types.NUMERIC);
st.execute();
if(!st.getString(5).equals("0")){
ADFUtils.executeByOperation("Commit");
}
ADFUtils.findIterator("XtglNjzyxxbVO1Iterator").executeQuery();
JSFUtils.refresh(table);
JSFUtils.refresh(richToolbar);
JSFUtils.addFacesInformationMessage(ErrorStringKey.formInternationString(ErrorStringKey.BATCH_SCUUESS) + "," +
ErrorStringKey.formInternationString(ErrorStringKey.ADDNUM_TIPS) + st.getString(5));
} catch (java.sql.SQLException s) {
s.printStackTrace();
throw new oracle.jbo.JboException(s);
} finally {
try {
if (st != null) {
st.close();
}
} catch (java.sql.SQLException s2) {
throw new oracle.jbo.JboException(s2);
}
}
JSFUtils.closePopup(addPop);//成功后关闭pop
} catch (Exception e) {
log.severe(e);
Noty.error(ErrorStringKey.OPERATOR_ERROR);
}
}
create or replace procedure XTGL_NJZYXXB_ADD(p_zyfxdms in varchar2,
p_njdm in varchar2,
p_xqdm in varchar2,
p_dwdm in varchar2,
count_num out number) is
/**
* 年级专业批量新增
* 2015年7月29日
p_zyfxdms 专业方向代码集
p_njdm 年级代码
p_xqdm 校区代码
p_dwdm 单位代码
*/
count_start number; --记录批量插入前数量
count_end number; --记录批量插入后数量
begin
select count(*) into count_start from xtgl_njzyxxb;
--批量插入操作
INSERT INTO xtgl_njzyxxb
(Njzydm,
Njzymc,
Nj,
Zyfxdm,
Sfxtzfx,
Sfqy,
Xqdm,
Ssdw,
Xz,
Pyccm,
Sfsd,
Zdzt)
SELECT p_njdm || Zyfxdm,
p_njdm || Zyfxmc,
p_njdm,
Zyfxdm,
Sfxtzfx,
'1',
p_xqdm,
p_dwdm,
Xz,
Pycc,
'0',
'0'
FROM XTGL_ZYFXXXSJZL
WHERE zyfxdm not in
(SELECT zyfxdm FROM xtgl_njzyxxb WHERE nj = p_njdm)
and zyfxdm in
--使用正则函数regexp_substr拆分字符串, eg将'1,2,3'拆分成'1','2','3'的集合。
(select regexp_substr(p_zyfxdms, '[^,]+', 1, rownum)
from dual
connect by rownum <=
length(regexp_replace(p_zyfxdms, '[^,]', null)));
--统计插入数量
select count(*) into count_end from xtgl_njzyxxb;
count_num := count_end - count_start;
end XTGL_NJZYXXB_ADD;
摘自:年级专业方向信息模块