we are using this code for deleting messege but not working ,
it is only wokring when i only assign value to sub1 variableassign
<html>
<body>
<%@ page language="java" import="java.sql.*" %>
<%
String[] list=request.getParameterValues("list");
// String list=request.getParameter("list");
int i;
String sub1;
for(i=0;i<list.length;i++)
{
try
{
sub1=list;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsn1","","");
Statement stmt=con.createStatement();
stmt.execute("delete from mes where sub='"+sub1+"'");
out.println(sub1);
stmt.close();
con.close();
}
catch(Exception e)
{out.println(e);}
}
%>
<a href="admin.jsp">Click here</a>
</body>
</html>
# 1
How to iterate through an array:
String[] array = getItSomehow();
for (int i = 0; i < array.length; i++) {
String item = array[i];
// Do your thing with 'item'.
}
Or even better, if you're using at least Java 1.5:String[] array = getItSomehow();
for (String item : array) {
// Do your thing with 'item'.
}
And I recommend you to connect only once, before the loop, to save time and to use PreparedStatement to avoid SQL injections. And don't forget to close at least the connection, otherwise you're leaking resources.
# 2
> How to iterate through an array:
> String[] array = getItSomehow();
> for (int i = 0; i < array.length; i++) {
>String item = array[i];
> // Do your thing with 'item'.
> }
Or even better, if you're using at least Java
> 1.5:[code]String[] array = getItSomehow();
> for (String item : array) {
>// Do your thing with 'item'.
> ode]
> And I recommend you to connect only once, before the
> loop, to save time and to use PreparedStatement to
> avoid SQL injections. And don't forget to close at
> least the connection, otherwise you're leaking
> resources.
it is not deleting any message from database but when i assign value as sub1="something"; then it is deleting but i dont understand why it is so please give me its solution