• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Generating SQL Insert scripts from Excel sheet

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
I am having the set of excel sheets which has the data to be populated to the table.

I need to create insert scripts to populate table rather than the importing the excel sheet as it is.

Any idea how can i do this? it can be either through any tool or Java class or even through Macro will do for me.

Thanks
 
author & internet detective
Posts: 42027
916
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parameswaran,
If you just want to import the columns in a different order, you can often configure your database's import facility to do so.

For something more complicated, you can write a script in any language that accesses the database. I'll assume you know Java since you are asking here. In Java, you would loop through the Excel spreadsheet and use a PreparedStatement to update the database. You'd probably want to use a batch update so it goes faster.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parameswaran ,

The best way is to use excel itself.
You can use expressions in excel cell.

Example assume following data

codeDescription
1015

say this is in cell A1,A2,B1,B2

You can write following expression in the cell C2

="insert into table mymaster values (" &A2&","&B2&");"

this will create the insert statement for those two values.

You can simply select C2 cell at right bottom & drag it down. That will create the insert statements for all inputs present in the column A & B.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic