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>

[878 byte] By [AnkitBansala] at [2007-11-27 10:00:41]
# 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.

BalusCa at 2007-7-13 0:32:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

AnkitBansala at 2007-7-13 0:32:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
it is working only if i assign value to sub1="some value";but not working with retrived value i dont understand why
AnkitBansala at 2007-7-13 0:32:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Just debug it?Use a debugger, or if you don't know how to do, then put simple sysout's at strategic locations to print the actual values to log.
BalusCa at 2007-7-13 0:32:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
please solve my this problem it is working well when i assigning any value to variable which using in delete query but not working with the value retrived from previous page please solve it i need it
AnkitBansala at 2007-7-13 0:32:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...