登录代码:
<head>
<title>11111</title>
</head>
<html><%
String _addDoctor="";
int age=0,sex=0,spDays[]=new int[14];
String did="",name="",level="",spe="",section="",spt="",phone="";;
Admin admin=(Admin)session.getAttribute("admin");
if(admin==null)
_addDoctor="<a href=\"login.jsp\">请先登录</a>";
else{
if(request.getParameter("add")!=null){
age=Integer.parseInt(request.getParameter("age"));
name=request.getParameter("name");
sex=Integer.parseInt(request.getParameter("sex"));
did=request.getParameter("did");
try{
spDays=Util.parseSpDays(spt);
}
catch(NumberFormatException nfe){
_addDoctor="非法输入";
}
int a=admin.addDoctor(did,name,age,sex,level,spe,spDays,phone,section);
switch(a){
case 1:
_addDoctor="插入成功";
break;
case 0:
_addDoctor="一般异常";
break;
case -1:
_addDoctor="数据库异常";
break;
case -2:
_addDoctor="已存在";
break;
}
}
}
%>
<body bgcolor="#FFFFFF">
<table width="770" height="423" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td height="421" bgcolor="#FFFFFF"><%@ include file = "../include/head.inc" %>
<table width="770" height="290" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<%@ include file="../include/admin.inc" %>
<td width="603" align="center" valign="top">
<table width="100%" height="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
<tr>
<td width="100%" height="257" align="center" valign="top" bgcolor="E3EDFF">
<br>
<p><%=_addDoctor%></p>
<form action="addDoctor.jsp?add=true" name="addDoctor" method="POST">
<p>编号:<input type="text" name="did" value="0"/></p>
<p>姓名:<input type="text" name="name"/></p>
<p>年龄:<input type="text" name="age" value="0"/></p>
</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
编号和姓名只能是空才能提交。填上就提示数据库异常
捕获异常代码
返回值-执行结果代码:
* 1-操作成功
* 0-抛出一般异常
* -1-抛出数据库异常
* -2信息已存在
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
conn.rollback();
res= -1;
}
catch(IllegalArgumentException iae){
Debug.log(Debug.getExceptionMsg(iae));
res= -2;
}
catch(Exception e){
res=0;
}
finally{
return res;
debug也是个定义类