mySQL trigger - prevent insert won't work for multiple inserts
This is expected behaviour: if you raise a SIGNAL, the entire statement is rolled back; if you set new.val to NULL, you insert NULL (I guess your client is messing with you by showing zeroes for NULL values).

You could work around this problem by not inserting ineligible records in the first place, something like this:

insert into test2 (val) select val from (
  -- values to insert
  select 1 as val union all 
  select 3
) i 
where not exists (
  select 1 from test2 t where abs(t.val - i.val) &lt;= 1
)