Posted By:
David_Thornton
Posted On:
Monday, April 26, 2004 04:53 PM
You must used a separate prepared statement for each table. A prepared statement is pre-compiled by the DBMS and this can not be done if the table(s) is not known.
Using the setString() method to set the value for a parameter marker in a prepared statement will always enclose the value in single quotes as string values in SQL statements must be enclosed in single quotes.
You need to do something along the lines of;
for( int ctr = 0; ctr < tables.length; ctr++) {
PreparedStatement pst = con.prepareStatement("delete from " + tables[ctr] + " where user_id = ?");
pst.setString(2,"userid");