I have some code that produces a set of primary key values that I want to delete from a database table.
long[] keysToDelete = { 0, 1, 2, 3 };
and I'd like to use a PreparedStatement to execute the equivalent of
DELETE FROM MyTable WHERE myPrimaryKey IN (0, 1, 2, 3);
Any idea how?
From stackoverflow
-
Two steps:
- Build up the PreparedStatement SQL String with the appropriate # of parameters.
- Loop over the array of values and bind each one to its parameter.
Unfortunately, there's no good way to bind an array all at once.
-
Not totally sure but this might help:
PreparedStatement pstmt = Connection.prepareStatement("DELETE FROM MyTable WHERE myPrimaryKey IN (?)"); pstmt.setArray(1, idArray); -
Is this what you are looking for?
http://stackoverflow.com/questions/337704/parameterizing-a-sql-in-clause#337817
Mike Samuel : no I don't think so but thanks
0 comments:
Post a Comment