• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to Fill ? For Prepared Statement in below case

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Insert Statement:

insert into temp2(NO,NAME,DATE) values(?,?,?)

I have recieve csv in any one of format below even it may change in formats.

How we insert this statement using PreparedStatement in java.

It may like this

NO,NAME,DATE
1,BALA,24-02-1987
2,BALA,24-02-1987

(OR)

NO,DATE,NAME
1,24-02-1987,BALA
2,24-02-1987,BALA

(OR)

DATE,NAME,NO
24-02-1987,BALA,1
24-02-1983,BALA,2
 
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
It's up to you to read the contents of the CSV file and figure out the order of its columns. You should end up with a list of objects/records which will contain the NO, NAME and DATE values from individual rows. You'll then use setString or setDate or whatever appropriate method with index corresponding to the bind variable (the question mark) of your SQL statement and the corresponding value you obtain from the record which keeps the data from the CSV file. If your case, the NO field comes first (with index 1), NAME second (index 2) and DATE third (index 3).

It would be also possible to create the SQL statement with fields ordered to match the order in CSV file. You'd need o create a new statement to process another file, of course, since it could have different order of fields. If you had lots of small files with lots of differently ordered columns, the first approach would be better.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:It's up to you to read the contents of the CSV file and figure out the order of its columns. You should end up with a list of objects/records which will contain the NO, NAME and DATE values from individual rows. You'll then use setString or setDate or whatever appropriate method with index corresponding to the bind variable (the question mark) of your SQL statement and the corresponding value you obtain from the record which keeps the data from the CSV file. If your case, the NO field comes first (with index 1), NAME second (index 2) and DATE third (index 3).

It would be also possible to create the SQL statement with fields ordered to match the order in CSV file. You'd need o create a new statement to process another file, of course, since it could have different order of fields. If you had lots of small files with lots of differently ordered columns, the first approach would be better.



can i just highlight the index does start at 1.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic