help!!!! jsp deletion issues
[nobr]hi
i have made a table using jsp to show the contents of a table from a database in a tabular format. the table rows have two options edit and delete. edit will show all the data in textboxes. this some how works.
delete option is giving one bug and one error
error: ResultSet is closed
bug: the data is being deleted. but instead of the row i want to be deleted,
only the first row is being deleted.
i am using SQLServer 2000 as my database;
i am using Apache Tomcat 5.5.17 as my webserver;
here is my code:
<%@ page errorPage="err.jsp" %>
<%@ page import="java.sql.*;" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:empdsn");
Statement st= con.createStatement();
Statement st2= con.createStatement();
//Statement st= con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs= st.executeQuery("select * from employeetable");
%>
<html>
<head>
<title>Employee Details</title>
</head>
<style>
.myLnk
{
color:#FF0000;
text-decoration:none;
}
.myLnk:hover
{
color:white;
text-decoration:underline;
}
</style>
<body bgcolor="#B7CEEC">
<table align="center">
<tr bgcolor="#808000">
<th>employee id</th>
<th>employee name</th>
<th>employee address</th>
<th>employee salary</th>
<th colspan="2">options</th>
</tr>
<%
String color="";
String act=request.getParameter("act");
String id=request.getParameter("id");
int i=1;
while(rs.next())
{
String empId=rs.getString(1);
if(i%2==0) color="#0000A0";
else color="#0000FF";
if(act!=null && id!=null)
{
if(act.equals("edit"))
{
%>
<form action="" name="empform">
<table align="center">
<tr>
<td> <input type="text" name="textid" value="<%= empId %>"></td>
<td><input type="text" name="textname" value="<%= rs.getString(2) %>"></td>
<td><input type="text" name="textaddress" value="<%= rs.getString(3) %>"></td>
<td><input type="text" name="textsalary" value="<%= rs.getString(4) %>"></td>
</tr>
</table>
</form>
<%}
elseif(act.equals("delete")){
//rs.absolute(Integer.parseInt(empId));
//rs.deleteRow();
//rs.updateRow();
out.println(empId);
int delres= st.executeUpdate("delete from employeetable where empid='"+empId+"'");
//ResultSet rs1= st.executeQuery("select * from employeetable");
while(rs.next())
{
//String delEmpId=rs1.getString(1);
//int delres= st.executeUpdate("delete from employeetable where empid='"+delEmpId+"'");
%>
<h1><font color="red" size="">DELETED SUCESSFULLY</font></h1><br>
<tr bgcolor="<%= color%>" style="color:white;font-weight:bold;">
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
<td><%= rs.getString(4) %></td>
</tr>
<%
//st2.executeUpdate(update_table);
}
}
%>
<%}else{ %>
<tr bgcolor="<%= color%>" style="color:white;font-weight:bold;">
<td><%= empId %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
<td><%= rs.getString(4) %></td>
<td><a href="showEmployeeTable.jsp?act=edit&id=<%=empId%>" class="myLnk">Edit</a></td>
<td><a href="showEmployeeTable.jsp?act=delete&id=<%=empId%>" class="myLnk">Delete</a></td>
</tr>
<%}
%>
<%
i++;
}
%>
</table>
</body>
</html>
can u please help me fix this? thanx in advance
shankha[/nobr]

