2017-03-17 2 views
0

私はnetbeansの初心者です。私のコードでは、insertコマンドが動作しています。しかし、更新、削除、および検索コマンドは機能しません。netbeansの更新、削除、検索コードの書き方

ここは私の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&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="pid"><br><br> 
     Name&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="pname"><br><br> 
     Mobile Number&nbsp<input type="text" name="pmobile"><br><br> 
     Disease&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="pdisease"><br><br> 

     <input type="submit" name="btn" value="ADD">&nbsp&nbsp&nbsp 
     <input type="submit" name="btn" value="SEARCH">&nbsp&nbsp&nbsp 
     <input type="submit" name="btn" value="UPDATE">&nbsp&nbsp&nbsp 
     <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. 

が問題を把握するために私を助けてください。ありがとうございました。

答えて

0

あなたが受け取ったエラーを含みます。これは、他の人が本当の問題を見つけ出すのに役立ちます。

ベスト・ウェイはサーブレットの使用です。このtutorial

Logger.getLogger(SERVLETNAME.class.getName()).log(Level.SEVERE, null, ex); 

を確認してくださいあなたのエラーをキャッチし、ログインするためにこのコードを使用します。

SERVLETNAMEはあなたのServletclassと元の名前は、変数

声明が確保されていない例外の名前ではなく良い練習用PreparedStament 詳細についてJDBC

です
関連する問題