ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 连接池调用实例

连接池调用实例

原创 Linux操作系统 作者:faq_dog 时间:2011-06-14 11:31:59 0 删除 编辑

DBConnection dbconnection = new DBConnection("customer_system");//从连接池内获得链接
     String sql = "update loginuser set usertype = ?," +
       " employname =?," +
       " apartment = ? " +
       " where userid = ?" ; //创建sql语句
     PreparedStatement prestate = dbconnection.getPreparedStatement(sql); //创建准备执行的状态
     prestate.setString(1, usertype); //设置参数
     prestate.setString(2, employname); //设置参数
     prestate.setString(3, apartment); //设置参数
     prestate.setString(4, userid); //设置参数
     
     int result = prestate.executeUpdate(); //执行更新,并返回更新的结果
     
     //再查询
     sql = "select * from loginuser";
     prestate = dbconnection.getPreparedStatement(sql); //创建准备执行的状态
     ResultSet rsSet = prestate.executeQuery();
     while (rsSet.next()) {
      Map temp = new HashMap();
      temp.put("userid", rsSet.getObject("userid"));
      temp.put("username", rsSet.getObject("username"));
      temp.put("employname", rsSet.getObject("employname"));
      temp.put("apartment", rsSet.getObject("apartment"));
      temp.put("usertype", rsSet.getObject("usertype"));
      arry.add(temp);
     }
     request.setAttribute("usercol", arry);
     rsSet.close();
     prestate.close();
     dbconnection.close();//关闭链接  

//怎么样?easy吧

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7861794/viewspace-697868/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-06-14

  • 博文量
    11
  • 访问量
    20829