• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how do i delete multiple records

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem solved ..
thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic