aspose file tools
The moose likes JDBC and the fly likes Problem in executing 'executeUpdate()' method in for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Problem in executing Watch "Problem in executing New topic
Author

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

Rahul Sarup
Greenhorn

Joined: Jun 03, 2004
Posts: 4
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

Joined: Jun 03, 2004
Posts: 4
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' !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in executing 'executeUpdate()' method in for loop
 
Similar Threads
uneasy code for beginners
using prepare statements
problem with string array
string array question
what is the difference between these.... String[] String... String