3 Votes Vote

how can I batchUpdate with a query that requires 2 parameters and only one of them is stored in a list

Posted by topdog 337 days ago Questions| list query friends All

I use Spring-JDBC to insert the list of facebook friends for a user in my MySQL database.

I have a final Long that contains the user uid and a List that contains the list of his friends.

my query is:

final String sqlInsert="insert into fb_user_friends(fb_uid,friend_uid) values(?,?)";

I create batch parameters using SqlParameterSourceUtils

SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(friendsList.toArray());

and I execute the insert using:

int[] insertCounts = this._jdbcTemplate.batchUpdate(sqlInsert,batch);

the problem here that the list contains only the 2nd parameter that's required by the query.

do I have to modify the friendsList to add to it another column or is there another way?

thanks!

Originally asked by: ufk on Stack Overflow

Discuss Bury


Who Voted for this Question