我是netbeans的初学者。在我的代码中,insert命令正在运行。但更新,删除和搜索命令无效。
这是我的html表单。
Patients.html
<html>
<head>
<title>Patients</title>
</head>
<body>
<h1><font color="1B407F">Patient Details</font></h1>
<form method="GET" action="Patients.jsp">
ID Number        <input type="text" name="pid"><br><br>
Name                 <input type="text" name="pname"><br><br>
Mobile Number <input type="text" name="pmobile"><br><br>
Disease              <input type="text" name="pdisease"><br><br>
<input type="submit" name="btn" value="ADD">   
<input type="submit" name="btn" value="SEARCH">   
<input type="submit" name="btn" value="UPDATE">   
<input type="submit" name="btn" value="DELETE">
</form>
</body>
这是jsp文件。
Patients.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Patients</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%
try
{
Connection c;
Statement s;
ResultSet rs;
String id=request.getParameter("pid");
String name=request.getParameter("pname");
String mobile=request.getParameter("pmobile");
String disease=request.getParameter("pdisease");
String btnvalue=request.getParameter("btn");
Class.forName("com.mysql.jdbc.Driver");
String path="jdbc:mysql://localhost/hospital";
c=DriverManager.getConnection(path,"root","");
s=c.createStatement();
if(btnvalue.equals("ADD"))
{
s.executeUpdate("insert into patients(P_NIC,P_Name,P_Mobile,Disease) values('"+id+"','"+name+"','"+mobile+"','"+disease+"')");
}
else if(btnvalue.equals("SEARCH"))
{
rs=s.executeQuery("select * from patients where P_NIC='"+id+"'" );
while(rs.next())
{
String i=rs.getString(1);
String n=rs.getString(2);
int m=rs.getInt(3);
String d=rs.getString(4);
System.out.print(i+n+m+d);
}
}
else if(btnvalue.equals("UPDATE"))
{
s.executeUpdate("update patients set P_Mobile='"+mobile+"' where P_NIC="+id+"");
}
else if(btnvalue.equals("DELETE"))
{
s.executeUpdate("Delete from patients where P_NIC="+id+"");
}
}
catch(ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(SQLException r)
{
{ System.out.println(r.getMessage());}
}
%>
</body>
The MySQL table patients contain 4 varchar fields such as P_NIC, P_Name, P_Mobile and Disease.
请帮我弄清问题。谢谢。