• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple insert into "MS Access" database

 
Sameer Ahmed
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to insert multiple values to the MSAccess database , i tried doing



but only the last row is stored in the table. Can somebody tell me where the problem is?
Any other alternative is also welcomed.

thanks
sameer
 
Wendy Gibbons
Bartender
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can see from the snippet of code you supplied you are only creating 1 row of data, one row with three values in it.
 
Sameer Ahmed
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad, forgot to put the for loop, code edited.
 
Wei Dai
Ranch Hand
Posts: 86
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for(int i=0;i<100;i++){
query="insert into ABC values (?, ?, ?)";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1,"a");

It should be
query="insert into ABC values (?, ?, ?)";
PreparedStatement pst = conn.prepareStatement(query);
for(int i=0;i<100;i++){
pst.setString(1,"a");
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wei is right. If that was done in a way that actually compiled, you'd be creating a new statement in every iteration of the loop, every of which would contain one row in the batch, and only execute the batch of the last created instance.

Also, you should specify columns into which you're inserting the values, see Always use column lists.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic