• Post Reply Bookmark Topic Watch Topic
  • New Topic

Coding Style with Database appropriate or not?  RSS feed

 
Azrael Noor
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • 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
 
Vicky Vijay
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • 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.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!