业务里的方法
public void delbatch(String ids) throws Exception {
String hql = "insert into 表名 where id号 in ("+ids;
System.out.println(hql);
iempDao.executeUpdate(hql);

}
再在在Action里写
/* 批量增加*/
public ActionForward delbatch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 提交过来的请求字符串
String id = request.getParameter("id");
// 最后个,改成)
StringBuffer sb = new StringBuffer(id);
sb.setCharAt(sb.length() - 1, ')');
// 调用业务
try {
iempService.inbatch(sb.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 return mapping.findForward("index");
//return getall(mapping, form, request, response); }
页面你可以这样构建:
 //批量增加
   function inbatch()
   {
      //判断是否选定
      var size = $(":checked").size();
      if (size==0)
      {
         alert("请选择先");
         return ;
      }
      //构造url
      var url = "${pageContext.request.contextPath}/emp.do?action=inbatch&id=";
      $(":checked").each(
          function(){
             url=url+this.value+",";
          }
      );
      location = url;
      
   }
   分析下:在页面你先在每个id前面放个复选框用来勾选你要传过去的id号,当你点批量增加时再调用我给你的这个函数,注意改地址!!!我这里的函数也是jquery做的,如果不熟悉可用常用的JavaScript。StringBuffer是为了构建hql里的语句,也就是,那个反小括号。

解决方案 »

  1.   

    for循环耗性能些,each本来就相当于for循环,而且简洁,省去许多代码。有优秀的干嘛不用呢
      

  2.   

    阅!我知道实现批量插入,要用到Statement中的
    addBatch(String sql) 
    将给定的 SQL 命令添加到此 Statement 对象的当前命令列表中。
      

  3.   

    想增加速度 还是看看 持久化 Hibernate
      

  4.   

    哎,楼主就做一个可导入吧,这样还要方便些,实际上就是读入操作,我们的批处理都是实现导入和导出,文本形式,或者是excel形式,都行,具体的今天不说了,哎,觉得好迷糊,今天太累了,做了东西没有做出来,郁闷.
      

  5.   

    把你要传的id值放到隐藏域里,通过js得到值,然后通过url传到Action里,通过reques。getP得到
      

  6.   

    --表 table_a( Id ,name ) 
    insert into table_a
    select id,name
    form (select 1 as Id,'pxp' as name Union
    select 2 ,'pxp2' Union
    select 3 ,'pxp3'
    略.................
    )
      

  7.   

    用 addBatch实现  批量插入