Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File parsing with header info dynamic

 
Vinay Singh
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • 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
 
Gayathri Chowduru
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic