This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes File parsing with header info dynamic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File parsing with header info dynamic" Watch "File parsing with header info dynamic" New topic
Author

File parsing with header info dynamic

Vinay Singh
Ranch Hand

Joined: Dec 15, 2004
Posts: 174
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


Technical quiz and interview questions   SCJP 6 mock practice test
Gayathri Chowduru
Ranch Hand

Joined: Oct 17, 2007
Posts: 42
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

Joined: Dec 15, 2004
Posts: 174
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

Joined: Feb 25, 2007
Posts: 1638

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)


apigee, a better way to API!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: File parsing with header info dynamic