• 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

File parsing with header info dynamic

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fellow ranchers
I would like to have your opinion on this problem.

I have a file which is to be imported into database.
The data is to be to be inserted in Table DATA_INSERT for eg.
The header varies with different database and this mapping is in DATA_MAPPING.
Now I am using hibernate to insert the record.

Let us assume file header is "Project Name"
Corresponding value for this is in DATA_MAPPING table so here it goes

TABLE_COLUMN_NAME HEADER_NAME
------------------ ------------
PROJ_NBR Project Name

This PROJ_NBR is column in DATA_INSERT.

Similarly the list goes for 170 columns(huge table)

The hibernate class is like

Class DataInsert
{
@PROJ_NBR
private String projectNbr;


public setProjectNbr(String proj){
this.projectNbr=proj
}

public getProjectNbr(){
return projectNbr;
}


Now how will I come to know when I am reading file that this data is
for which column(it can vary from databases)
and which setter to call ?

Thanks
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

as per your data,

Now how will I come to know when I am reading file that this data is
for which column(it can vary from databases)
and which setter to call ?

Does it mean do you want to save the entire file into the database? If so, To store large text files in to the database, java supports a data type like CLOB (Character Language OBject). You can write the getters and setters for this particular data type.
 
Vinay Singh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well had it been that easy that I would not have posted it here
This is tab separated file with 150 blocks of data in each row.
I have to insert data of each block in respective column, mapping of which is as I have described above
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vinay Singh:
I have to insert data of each block in respective column, mapping of which is as I have described above



You have to specify one more mapping that maps the column name to the setter name. I am not sure but hibernate must be generating this information somewhere since you are using annotations to specify the relationship between a column and a field in the data object.
(I am not aware of Hibernate though)
reply
    Bookmark Topic Watch Topic
  • New Topic