0

I am executing two prepared statement for deleting two records of different id. i want to delete both records in a single prepared statement execution my code is like this

String sqlDelete,sqlSelect2; sqlDelete = "delete from vul_detail where scanno=? and id=?";// PreparedStatement ps2=conn.prepareStatement(sqlDelete); // System.out.println("PS Created Successfully"); ps2.setString(1, "scan_2"); ps2.setInt(2, 2); // ps2.setInt(3, 5); ps2.executeUpdate(); System.out.println("first record deleted"); ps2.setString(1, "scan_2"); ps2.setInt(2, 5); ps2.executeUpdate(); System.out.println("second record deleted"); sqlSelect2="select * from vul_detail;"; stmt=conn.createStatement(); System.out.println("select query created"); ResultSet rs2 = stmt.executeQuery(sqlSelect2); 

I tried query as

sqlDelete = "delete from vul_detail where scanno=? and id=?,?"; PreparedStatement ps2=conn.prepareStatement(sqlDelete); System.out.println("PS Created Successfully"); ps2.setString(1, "scan_2"); ps2.setInt(2, 2); ps2.setInt(3, 5); ps2.executeUpdate(); 

I am getting exception in this please help

1
  • You already got an answer that should fix this issue (since it's quite obvious). But please remember to include the exception in future questions instead of just saying "I am getting exception". Commented Sep 25, 2013 at 7:42

1 Answer 1

3

The syntax for the "IN" condition is:

expression in (value1, value2, .... value_n); 

In your example:

sqlDelete = "delete from vul_detail where scanno = ? and id in (?, ?)"; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.