This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes how do i delete multiple records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how do i delete multiple records" Watch "how do i delete multiple records" New topic
Author

how do i delete multiple records

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
tried the code for deletion:
<%
Connection con=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
boolean y=false;
int i;
String xy=(String)session.getAttribute("y");
%>

<form action="phd_projects_deleted.jsp" method="post" onSubmit="return confirm_me()">
<table border="1" cellpadding="1" cellspacing="1">

<th>
<% out.print("Project Title"); %>
</th>

<th>
<% out.print("Year"); %>
</th>
<th>
Delete Records
</th>

<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();
int count=0;
rs=stmt.executeQuery("select top 4* from phd_projects where user_login='"+xy+"' order by phd_id");
while(rs.next()) {
count++;


%>

<tr>

<td><% out.print(rs.getObject(2).toString()); %>
</td>
<td><% out.print(rs.getObject(5).toString()); %>
</td>

<td>
<input type="checkbox" name="var_phd_id" value="+rs.getString("phd_id")">
</td>
</tr>
<%

}
if(count==0)
{
{
out.println("<p><b>No records found</b></p>");
}
}
}
catch(Exception e)
{
System.out.println("exception in block"+e);
}
rs.close();
con.close();
%>
</table>
<p> </p>
<input type="submit" name="submit" value="delete">
<input type="reset" name="cancel" value="cancel">
</form>
phd_id is my identtity column in the phd_projects table..
and on submitting the form.. in the next page..
wrote this :
String id[]=request.getParameterValues("var_phd_id");
String xy=(String)session.getAttribute("y");


try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();
String ids[]=request.getParameterValues("var_project_id");
rs=stmt.executeQuery("delete from phd_projects where phd_id in(id)");


stmt.close();

con.close();
}
catch(Exception e)
{
System.out.println(e);

}

%>

bt it gives the error as invalid column name 'id'
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please use code tags.

'id' is an array, you need to iterate through the array and add each value to the query. (This would be much fatser using a StringBuffer)

Dave
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
hi tkx for the reply..
bt some problem still coming on deletion:
in String sql="delete from phd_projects where phd_id in("+selectedId+")";
iam getting a sql exception..incorrect syntax near '='.
and the ids that are being printed out are like this:
phd_ids="10",="11",="12"
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
Problem solved ..
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i delete multiple records
 
Similar Threads
updation..error..
deletion problem..
problem in browsing
what could be the reason behind this exception?
display problem.