zoukankan      html  css  js  c++  java
  • 调用存储过程

    引用:http://blog.sina.com.cn/s/blog_58b90369010008xy.html

    MYSQL
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `freewap`.`add_user` $$
    CREATE DEFINER=`root`@`localhost` PROCEDURE `add_user`(
     IN name TEXT,
            IN pwd TEXT,
            IN email TEXT,
     IN qq TEXT,
      IN birthday DATE,
      IN sex tinyint,
     IN pwdquestion TEXT,
     IN pwdanswer TEXT,
     IN firstpwd TEXT
     )
    BEGIN
        INSERT INTO `tbl_user`(u_name, u_pwd, u_email, u_qq, u_birthday, u_sex, u_pwdquestion, u_pwdanswer, u_firstpwd)
        VALUES (name,pwd,email,qq,birthday,sex,pwdquestion,pwdanswer,firstpwd);
      END $$
    DELIMITER ;
     
     
    JSP代码片断:
     private  CallableStatement cStmt = null;
    //调用存储过程查询,需要返回查询结果

     public ResultSet callQuery (String proc)
     {
      rs=null;
      try{
          cStmt=conn.prepareCall("CALL "+proc +";",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
          rs=cStmt.executeQuery();
      }
      catch (SQLException ex)
      {
       System.err.println("DAO.DBBean.executeQuery() ERR :"+ex.getMessage());
      }
      return rs;
     }
     
     //调用存储过程更新,不需要返回
     public void callUpdate (String proc)
     {
      rs=null;
      stmt=null;
      try{
       System.out.println("{CALL "+proc+"}");
       cStmt=conn.prepareCall("{CALL "+proc+"}");
       cStmt.execute();
      }
      catch (SQLException ex)
      {
       System.err.println("DAO.DBBean.callUpdate() ERR :"+ex.getMessage());
      }
     }
     
    //插入数据。添加用户,在注册时使用
     public void addUser(UserBean user) throws SQLException {
      DBBean dbbean = new  DBBean();
      dbbean.openConn();
      try
         {
       StringBuffer sql = new StringBuffer();
           sql = new StringBuffer("add_user(");
           sql.append("'" + user.getU_name() + "',");
           StrEncrypt strencrypt=new StrEncrypt();
           sql.append("'" + strencrypt.EncryptStr(user.getU_pwd()) + "',");
           sql.append("'" + user.getU_email() + "',");
           sql.append("'" + user.getU_qq() + "',");
           sql.append("'" + new java.sql.Date(user.getU_birthday().getTime()) + "',");
           sql.append("" + user.getU_sex() + ",");
           sql.append("'" + user.getU_pwdquestion() + "',");
           sql.append("'" + user.getU_pwdanswer() + "',");
           sql.append("'" + user.getU_pwd() + "'");
           sql.append(")");
           dbbean.callUpdate(sql.toString());
         }
         catch (Exception sqle)
         {
             sqle.printStackTrace();
         }
         finally
         {
          dbbean.closeCall();
         }
       }
  • 相关阅读:
    poj 2763 Housewife Wind
    hdu 3966 Aragorn's Story
    poj 1655 Balancing Act 求树的重心
    有上下界的网络流问题
    URAL 1277 Cops and Thieves 最小割 无向图点带权点连通度
    ZOJ 2532 Internship 网络流求关键边
    ZOJ 2760 How Many Shortest Path 最大流+floyd求最短路
    SGU 438 The Glorious Karlutka River =) 拆点+动态流+最大流
    怎么样仿写已知网址的网页?
    5-10 公路村村通 (30分)
  • 原文地址:https://www.cnblogs.com/sode/p/2984884.html
Copyright © 2011-2022 走看看