• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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)
 
Forget Steve. Look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic