• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple insert into "MS Access" database

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad, forgot to put the for loop, code edited.
 
Ranch Hand
Posts: 86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic