⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enrolladd.java

📁 网上银行管理系统
💻 JAVA
字号:
package cn.edu.ccut;

import javax.naming.Context;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.io.IOException;
import java.sql.*;

/**
 * Created by IntelliJ IDEA.
 * User: hvst
 * Date: 2008-8-21
 * Time: 14:05:23
 * To change this template use File | Settings | File Templates.
 */
public class EnrollAdd extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

        String strSql        = "";
        String strSqll       = "";
        String strSqlll      = "";
        String strSqlV       = "";
        String strSqlVI      = "";
        String strUserName   = "";
        String strPassWord   = "";
        String strSex        = "";
        String strAddress    = "";
        String strUserCode   = "";
        String strTime       = "";
        String strMonth      = "";
        String strDay        = "";
        String strDate       = "";
        String strPhoneNum   = "";
        String strMenu       = "";
        String strLogo       = "";
        String userName      = "";

        Context ctx          = null;
        DataSource ds        = null;
        Connection conn      = null;
        Statement stmt       = null;
        ResultSet rs         = null;
        PrintWriter out      = null;

        try {
            out = response.getWriter();
            HttpSession session = request.getSession();

            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost/bank?useUnicode=true&characterEncoding=gb2312", "root", "");

            stmt = conn.createStatement();

            strUserName   = request.getParameter("username");
            userName      = StringUtil.iso2gb2312(strUserName);
            strPassWord   = request.getParameter("userpassword");
            strSex        = request.getParameter("sex");
            strAddress    = request.getParameter("address");
            strUserCode   = request.getParameter("usercode");
            strTime       = request.getParameter("startTime");
            strPhoneNum   = request.getParameter("phonenum");
            strLogo       = request.getParameter("logo");

            strSqll =" select max(userid) as a " +
                    " from UserMessageT ";
            rs = stmt.executeQuery(strSqll);
            String strUserId = "";
            while (rs.next()){
               strUserId = String.valueOf(Integer.parseInt(rs.getString("a"))+1); //String。valueof转为字符类型,Integer。parseInt转为整型
            }

            session.setAttribute("userId",strUserId); //创建session会话!!
            strSql =" insert into UserMessageT(userid,username,userpassword,usersex,address,usercode,birth,phonenum,menu) " +
                    " values ('" + strUserId + "','" + userName + "','" + strPassWord + "','" + strSex + "','" + strAddress + "','" + strUserCode + "','" + strTime  + "','" + strPhoneNum + "','" + strPhoneNum + "')";

            strSqlll = "insert into enrollmessaget (userid,userpassword,logo)" +
                       " values ('" + strUserId + "','" + strPassWord + "','" + strLogo + "')";
            strSqlV=" insert into `useroperationt`(userid,operated,timed,operatedmoney)" +
                    " values ('" + strUserId + "','3',sysdate(),'0')";
            strSqlVI=" INSERT INTO `slimsy`(userid,leftover) " +
                    " VALUES('" + strUserId + "','0') ";
            stmt.executeUpdate(strSql);
            stmt.executeUpdate(strSqlll);
            stmt.executeUpdate(strSqlV);
            stmt.executeUpdate(strSqlVI);

            response.sendRedirect("/liu/jsp/operate.jsp"); //不传参数的跳页

        } catch (Exception e) {
            out.println("<script language='javascript'>");
            out.println("alert('注册失败!');");
            out.println("window.history.back();");
            out.println("</script>");
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } finally {
            try {
                if(stmt != null) stmt.close();
                if(conn != null) conn.close();
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -