Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String sql =
- "SET NOCOUNT ON; "
- + "DECLARE @id INT = ?; "
- + "DECLARE @col2 VARCHAR(10) = ?; "
- + "DECLARE @col3 VARCHAR(10) = ?; "
- + "INSERT INTO mytable "
- + "SELECT @id, @col2, @col3 "
- + "WHERE NOT EXISTS (SELECT 1 FROM mytable "
- + " WHERE id = @id AND col2 = @col2 AND col3 = @col3);";
- PreparedStatement ps = conn.prepareStatement(sql);
- for (int i = 0; i < 4; i++) {
- ps.setInt(1, i);
- ps.setString(2, String.format("foo%s", i));
- ps.setString(3, String.format("bar%s", i));
- ps.addBatch();
- }
- ps.executeBatch();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement