2017-06-06 91 views
0
<html> 
<%@ page import="java.sql.*" %> 
<head> 
<title>Sarvotam List</title> 
<link rel="stylesheet" href="Styles/main.css"> 
</head> 
<body> 
<div class="seg"> 
    <form action="main.jsp" method="post"> 
    <table class="data" align="center" width=80%> 
     <tr> 
      <th width=20%>Qualification Exam</th>  
      <th width=20%>Course Type</th> 
      <th width=20%>Duration</th> 
      <th width=20%>Number of Cheques</th> 
      <th width=20%>Course_Category</th> 
     </tr> 
     <tr> 
      <td width=20% align="center"><input type="text" name="qual" 
    width=20%></td> 
      <td width=20% align="center"><input type="text" name="ctype" 
    width=20%></td> 
      <td width=20% align="center"><input type="number" name="dur" 
    width=20%></td> 
      <td width=20% align="center"><input type="number" name="che" 
width=20%></td> 
      <td width=20% align="center"><select name="opt"> 
        <option id="ENG">ENG</option> 
        <option id="MED">MED</option> 
        <option id="OTH">OTH</option> 
        <option id="PG">PG</option> 
       </select> 
     </tr> 
     <tr> 
      <td width=20% align="center"><input type="text" name="qual" 
width=20%></td> 
      <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="dur" 
    width=20%></td> 
      <td width=20% align="center"><input type="number" name="che" 
width=20%></td> 
      <td width=20% align="center"><select name="opt"> 
        <option id="ENG">ENG</option> 
        <option id="MED">MED</option> 
        <option id="OTH">OTH</option> 
        <option id="PG">PG</option> 
       </select> 
     </tr> 
     <tr> 
      <td width=20% align="center"><input type="text" name="qual" 
width=20%></td> 
      <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="dur" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="che" 
width=20%></td> 
      <td width=20% align="center"><select name="opt"> 
        <option id="ENG">ENG</option> 
        <option id="MED">MED</option> 
        <option id="OTH">OTH</option> 
        <option id="PG">PG</option> 
       </select> 
     </tr> 
     <tr> 
      <td width=20% align="center"><input type="text" name="qual" 
width=20%></td> 
      <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="dur" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="che" 
width=20%></td> 
      <td width=20% align="center"><select name="opt"> 
        <option id="ENG">ENG</option> 
        <option id="MED">MED</option> 
        <option id="OTH">OTH</option> 
        <option id="PG">PG</option> 
       </select> 
     </tr> 
     <tr> 
      <td width=20% align="center"><input type="text" name="qual" 
    width=20%></td> 
      <td width=20% align="center"><input type="text" name="ctype" 
width=20%></td> 
      <td width=20% align="center"><input type="number" name="dur" 
    width=20%></td> 
      <td width=20% align="center"><input type="number" name="che" 
width=20%></td> 
      <td width=20% align="center"><select name="opt"> 
        <option id="ENG">ENG</option> 
        <option id="MED">MED</option> 
        <option id="OTH">OTH</option> 
        <option id="PG">PG</option> 
       </select> 
     </tr> 
      </table> 
     <center><button id="submit" name="save">Submit</button></center> 

<%    try{ 
    ResultSet rs=null; 
    Statement st=null; 
    Connection conn = null; 
    Class.forName("oracle.jdbc.driver.OracleDriver"); 
      conn = 
    DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", 
    "system", "parents94"); 
      st=conn.createStatement(); 
      int i=0; 
      String s = request.getParameter("save"); 
      String[] qual=request.getParameterValues("qual"); 
      String[] ctype=request.getParameterValues("ctype"); 
      String[] dur=request.getParameterValues("dur"); 
      String[] noc=request.getParameterValues("che"); 
      String[] cou=request.getParamterValues("opt"); 
      if(s!=null) 
      while(qual[i].length()!=0){ 
       st.executeUpdate("insert into SCHOL_COURSE_MASTER values('"+qual[i]+"','"+ctype[i]+"','"+dur[i]+"','"+noc[i]+"','"+cou[i]+"')"); 
       i++; 
      } 
     conn.close(); 
     st.close(); 
      } 
catch(Exception e) 
    { 
     e.getMessage(); 
    } 
%> 
</form> 
</div> 
    </body> 
</html> 

這是我的代碼 我需要從用戶輸入表中,並添加到數據庫 所有的連接工作 但SQL查詢不會導致任何改變數據庫 我只需要在如何代碼它有助於對按工作提交按鈕在HTML中添加操作按鈕

+0

的DB更新相關的代碼可以在同樣的jsp?你的main.jsp相關代碼在哪裏?永遠不要在jsp上使用scriptlet。保留查詢日誌並嘗試查看要在數據庫中執行的查詢。 –

回答

3

添加提交類型按鈕:

<center> 
    <button type="submit" id="submit" name="save">Submit</button> 
</center> 
+0

如何在其中運行代碼部分? –

+1

你的表單動作應該是你想要運行的代碼的文件 – Kzy

0

首先你可能要檢查是否 點擊事件是否被觸發?

然後嘗試,如果你得到正確的值來打印,或者如果你有錯誤不是null

其如果包括它在您的文章更好

+0

這裏沒有錯誤,但它不起作用 ,你能告訴我如何檢查點擊事件是否被觸發 –

+0

它在

檢查main.jsp中的數據是否正確 – kirin19