i have created a delete.jsp page which checks for datatype entered in the fields and when user enters the student id will delete it from database.i am succesfull while following insert.jsp but i am geting proublem while updating and deleting. i have linked insertiion,updation and deletion jsp files to 1 home.html page which run in tomcat server. When i click delete or update it shows me fields to modify but when i click submit nothing happens. i have a feeling something about preparestatement not working. plz help
my database is as below
SQL> desc student_info;
Name Null? Type
----------------------------------------- -------- -------------------
SID NUMBER(9)
SNAME VARCHAR2(8)
SADD VARCHAR2(16)
and my delete.jsp page is as below
<html>
<script language='javascript'>
function isValid()
{
if(f.stu_id.value=="")
{
alert(f.stu_id.name+" "+"field missing");
f.stu_id.focus();
return false;
}
if(isNaN(f.stu_id.value))
{
alert("stu_id should be numeric value");
f.stu_id.focus();
return false;
}
return true;
}
</script>
<body>
<form name=f action='./delete' method='post' onSubmit='return isValid()'>
<table border=1 cellpadding =7 cellspacing=7 align=center>
<caption><i><font size=4><u>Delete records</caption>
<tr>
<th>student id<th><input type="text" name="stu_id"></tr>
<tr>
<th>click<th><input type="submit" value="delete"></tr>
</table>
</form>
</body>
</html>
and my deleterecords.java file
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.sql.PreparedStatement;
public class deletedemo extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
{
Connection con=null;
PreparedStatement ps=null;
int rs=0;
try
{
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
pw.println("<html><form target='display'>");
int sid=Integer.parseInt(req.getParameter("stu_id"));
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:odbc:thin:@localhost:8080:ravi","system","tiger");
ps=con.prepareStatement("delete from student_info where stu_id=?");
ps.setInt(1,sid);
rs=ps.executeUpdate();
if(rs!=1)
pw.println("<h2>student id is proublem</h2>");
else
pw.println("<h2 style='position:absolute;left:50;top:50'> one record deleted </h2>");
ps.close();
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
doPost(req,res);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}