• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in executing 'executeUpdate()' method in for loop

 
Rahul Sarup
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all !
I am trying to add a group of records in MS ACCESS database using the following code:

// stringArray is an array of String i.e String[]

for(int i=0; i<stringArray.length; i++) {
String str_item = (stringArray[i]).trim();
ps = con.prepareStatement(
insert into TABLE_NAME (sr_no, str_item) values (?, ?) );
ps.setInt(1, sr_no);
ps.setString(2, str_item);
ps.executeUpdate();
}

here, if the size of the string array is 1, the code is working. But for size > 1, general DB error is coming...

Is this the problem with ACCESS DB? because i have successfully implemented something similar with Oracle.

Please HELP !!!
Thanks in advance !
 
Rahul Sarup
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well guys,
i have found the solution to the problem.
The code was perfectly fine. The problem was with the DB design.
I had kept the 'sr_no' field as Primary Key, so it was not allowing multiple entries corrosponding to same 'sr_no' !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic