Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Coding Style with Database appropriate or not?

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all

Wanted to know the following is style i am following in code to call database (not using any framework), so wanted to know the way i am inserting data is correct or not..

I have to run 20 Insert queries to put various types of data into database(in different tables), processing one request..

so i open the database connection once and do process and insert
do process and insert
do process and insert
and goes on for 20 and save it and close database connection

In loops, multiple inserts also goes on!!!

Is this appropriate style of coding in java? or any other coding style fits to this idea/criteria?


Sharing a Code with you...Please advice on database part




Thank you in advance
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refer the below link,


JDBC Batch


JDBC Batch process
 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
Could you please explain in brief that will that help in performance issue in execution...

like which one is fast

> to again and again put data in database using insert
> to put all in batch and then call insert?

or will they both take same time?

thank you
 
Marshal
Posts: 76070
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don’t know about the code, but the formatting was pretty bad:
  • Lines too long
  • No space after commas
  • No spaces around binary operators
  • Mixing tabs and spaces for indenting
  • I have corrected some of those things.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic