<%@ page language="java" pageEncoding="utf-8" import="java.sql.*" %>
<%request.setCharacterEncoding("gb2312"); %>
<script language="JavaScript">
function check(theForm)
{
if(theForm.bh.value.length!=7)
{
alert("职工编号必须为7位!");
theForm.bh.focus();
return (false);
}
if(theForm.xm.value=="")
{
alert("请输入姓名!");
theForm.xm.focus();
return (false);
}
if(theForm.csrq.value=="")
{
alert("请输入出生日期!");
theForm.csrq.focus();
return (false);
}
if(theForm.jbgz.value=="")
{
alert("请输入基本工资!");
theForm.jbgz.focus();
return (false);
}
if(theForm.gwjt.value=="")
{
alert("请输入岗位津贴!");
theForm.gwjt.focus();
return (false);
}
return (true);
}
</script>
<html>
<head><title>职工增加</title></head>
<body>
<div align="center">
<p>职工增加</p>
<form id="forml" name="forml" method="post" action="ZgZj0.jsp" onSubmit="return check(this)">
<table border="1">
<tr><td>编号</td><td><input name="bh" type="text" id="bh"/></td></tr>
<tr><td>姓名</td><td><input name="xm" type="text" id="xm"/></td></tr>
<tr><td>性别</td><td><input type="radio" name="xb" value="男" checked="checked"/>男
<input type="radio" name="xb" value="女"/>女
</td></tr>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();//导入包时,复制到lib并右键包Build Path
String url="jdbc:mysql://localhost:3306/rsgl";
String user="root";
String password="15876365651";
Connection conn=DriverManager.getConnection(url,user,password);
String sql="select*from bmb order by bmbh";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
%>
<tr><td>部门</td>
<td><select name="bm">
<%
while(rs.next())
{
String bmbh=rs.getString("bmbh");
String bmmc=rs.getString("bmmc");
%>
<option value="<%=bmbh%>"><%=bmmc%></option>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</select>
</td></tr>
<tr><td>出生日期</td><td><input name="csrq" type="text" id="csrq"/></td></tr>
<tr><td>基本工资</td><td><input name="jbgz" type="text" id="jbgz"/></td></tr>
<tr><td>岗位津贴</td><td><input name="gwjt" type="text" id="gwjt"/></td></tr>
</table>
<br>
<input name="submit" type="submit" value="确认"/>
<input name="reset" type="reset" value="重置"/>
</form>
</div>
</body>
</html>
<%@ page language="java" pageEncoding="utf-8" import="java.sql.*" %>
<%request.setCharacterEncoding("gb2312"); %>
<html>
<head><title></title></head>
<body>
<%
String bh=request.getParameter("bh");
String xm=request.getParameter("xm");
String xb=request.getParameter("xb");
String bm=request.getParameter("bm");
String csrq=request.getParameter("csrq");
String jbgz=request.getParameter("jbgz");
String gwjt=request.getParameter("gwjt");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();//导入包时,复制到lib并右键包Build Path
String url="jdbc:mysql://localhost:3306/rsgl";
String user="root";
String password="15876365651";
Connection conn=DriverManager.getConnection(url,user,password);
String sql="insert into zgb(bh,xm,xb,bm,csrq,jbgz,gwjt)";
sql=sql+"values('"+bh+"','"+xm+"','"+xb+"','"+bm+"','"+csrq+"'";
sql=sql+","+jbgz+","+gwjt+")";
Statement stmt=conn.createStatement();
int n=stmt.executeUpdate(sql);
if(n>0){
out.print("职员记录增加成功!");
}
else{
out.print("职员记录增加失败!");
}
stmt.close();
conn.close();
}
catch(Exception e){
out.print(e.toString());
}
%>
</body>
</html>