本系列博客汇总在这里:企业信息管理系统汇总


目录


用户更新

新建 update.jsp 文件

源码见附件一。

企业信息管理系统(8)_用户更新_sql

效果图

修改工资。

企业信息管理系统(8)_用户更新_java_02

附件

附件一

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="com.wyx.ces.*" %>
<%@page import="com.wyx.ces.model.*" %>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">

a
{
text-decoration: none;
}

body
{
font-size:12px;
color: #033D61;
}


.tableb
{
border-collapse: collapse;
width: 60%;
}


.tableb th, .tableb td
{
border: 1px solid #33A9D0;
height: 20px;
}
th
{
background-color: #E7F2FA;
}
</style>

</head>

<body>
<span>当前位置:用户管理>>用户添加</span>
<%
request.setCharacterEncoding("UTF-8");
//获得表单提交过来的参数
String username = request.getParameter("username");
String password = request.getParameter("password");
String gender = request.getParameter("gender");
String birthday = request.getParameter("birthday");
String address = request.getParameter("address");
String sal = request.getParameter("sal");
String userIdStr = request.getParameter("userId");

//把参数转换成相应的数据类型
Integer genderInt = null;
java.util.Date birthdayDate = null;
BigDecimal salBD = null;
Integer userId = null;
if(gender != null)
{
genderInt = new Integer(gender);
}
if(birthday != null)
{
birthdayDate = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
}
if(sal != null)
{
salBD = new BigDecimal(sal);
}
if(userIdStr != null)
{
userId = new Integer(userIdStr);
}

CSUsr user = new CSUsr();
user.setAddress(address);
user.setBirthday(birthdayDate);
user.setGender(genderInt);
user.setPassword(password);
user.setUsername(username);
user.setSal(salBD);
user.setUserId(userId);
//定义添加用户sql
String sql = "update cs_user set username = ?, password=?, gender=?, birthday=?, address=?, sal=? where user_id = ?";
PreparedStatement pstmt = null;
try
{
pstmt = DBUtil.getPstmt(sql);
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.setInt(3, user.getGender());
pstmt.setDate(4, new java.sql.Date(user.getBirthday().getTime()));
pstmt.setString(5, user.getAddress());
pstmt.setBigDecimal(6, user.getSal());
pstmt.setInt(7, user.getUserId());
pstmt.executeUpdate();
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
DBUtil.closeResUpdate(pstmt);
}

//重定向到列表页面
response.sendRedirect("/ces/tab/tab.jsp");
%>
</body>
</html>

如有错误,欢迎指正!