0

I have a SQL statement that needs to be executed multiple times with a list, and right now I'm using @SQLBATCH to do this.

@SqlBatch("INSERT INTO table (name, id) values (:names, :id)")
public abstract void addName(
    @Bind("names") List<String> names,
    @Bind("id") long id);

I would like to return an int of the number of rows affected. So I looked into @SQLUpdate, but it seems like @SQLUpdate doesn't take a list as a parameter.

@SqlUpdate("INSERT INTO table (name, id) values (:names, :id)")
public abstract int addName(
    @Bind("names") List<String> names,
    @Bind("id") long id);

I'm getting this error: UnableToCreateStatementException: Exception while binding.

Is there any way I can return an int of the number of rows affected?

user6800688
  • 145
  • 3
  • 11

1 Answers1

0

I don't think that you can use @Update this way.

Maybe you could employ @BindIn in some way I do not see but it is mainly to construct in-conditions like id in ('a', 'b', 'c', 'd').

Also I don't think that you need it because the number of elements in your names parameter already gives you the number of inserts that @SqlBatch executes.

So in the calling code you could just use name.size() to get the number of inserts that have been executed.

martinw
  • 364
  • 2
  • 7