OAF : Reading the data form the csv file and loading the data to table
PFR Logic :
if(pageContext.getParameter("save")!=null)
{
DataObject fileUploadData = (DataObject)pageContext.getNamedDataObject("FileUploadItem");
String fileName = null;
String contentType = null;
Long fileSize = null;
Integer fileType = new Integer(6);
BlobDomain uploadedByteStream = null;
BufferedReader in = null;
try
{
fileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
contentType = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, fileName);
in = new BufferedReader(new InputStreamReader(uploadedByteStream.getBinaryStream()));
fileSize = new Long(uploadedByteStream.getLength());
System.out.println("fileSize : " + fileSize);
System.out.println("fileName :"+fileName);
System.out.println("contentType :"+contentType);
} catch (NullPointerException ex)
{
throw new OAException("Please Select a File to Upload", OAException.ERROR);
}
writeLinesToVO(pageContext,webBean, in);
}
-----------------------
public void writeLinesToVO(OAPageContext pageContext, OAWebBean webBean , BufferedReader in )
{
xxlearn.oracle.apps.fnd.server.LearnAMImpl am = (xxlearn.oracle.apps.fnd.server.LearnAMImpl)pageContext.getApplicationModule(webBean);
XxcusCsvFileBlobEOVOImpl vo = am.getXxcusCsvFileBlobEOVO1() ;
XxcusCsvFileBlobEOVORowImpl row = null;
try
{
//Open the CSV file for reading
String lineReader = "";
long t = 0;
String[] linetext;
while (((lineReader = in.readLine()) != null))
{
//Split the deliminated data and
if (lineReader.trim().length() > 0)
{
System.out.println("lineReader" + lineReader.length());
linetext = lineReader.split(",");
t++;
int lineLength = linetext.length;
System.out.println("line text length is : " + lineLength);
if(lineLength ==3)
{
row = (XxcusCsvFileBlobEOVORowImpl)vo.createRow();
Number fileID = am.getOADBTransaction().getSequenceValue("XXCUS_CSV_FILE_ID_S");
row.setFileId(fileID);
row.setOrgcode(linetext[0]);
row.setSegment(linetext[1]);
row.setStatus(linetext[2]);
}
for (int k = 0; k < lineLength; k++)
{
System.out.println(linetext[k]);
} //for
}//if
} //while
am.getOADBTransaction().commit();
}//try
catch (IOException e)
{
}
throw new OAException("Data Saved Successfully", OAException.INFORMATION) ;
}
Database Table Structure
-----------------------------------------------------------------------------------------
CREATE TABLE xxcus_csv_file_blob
(
file_id INTEGER
, status varchar2(100)
,segment varchar2(100)
,orgcode varchar2(10)
,creation_date DATE
,created_by NUMBER
,last_update_date DATE
,last_updated_by INTEGER
,last_update_login INTEGER
,CONSTRAINT xxcus_csv_file_id PRIMARY KEY (file_id)
) ;
create sequence XXCUS_CSV_FILE_ID_S ;
-----------------------------------------------------------------------------------------
PS: Above coding is not totally mine, i copied from the below blog
http://rajubandam.blogspot.in/2014/01/uploading-csv-file-into-data-base-table.html
PFR Logic :
if(pageContext.getParameter("save")!=null)
{
DataObject fileUploadData = (DataObject)pageContext.getNamedDataObject("FileUploadItem");
String fileName = null;
String contentType = null;
Long fileSize = null;
Integer fileType = new Integer(6);
BlobDomain uploadedByteStream = null;
BufferedReader in = null;
try
{
fileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
contentType = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, fileName);
in = new BufferedReader(new InputStreamReader(uploadedByteStream.getBinaryStream()));
fileSize = new Long(uploadedByteStream.getLength());
System.out.println("fileSize : " + fileSize);
System.out.println("fileName :"+fileName);
System.out.println("contentType :"+contentType);
} catch (NullPointerException ex)
{
throw new OAException("Please Select a File to Upload", OAException.ERROR);
}
writeLinesToVO(pageContext,webBean, in);
}
-----------------------
public void writeLinesToVO(OAPageContext pageContext, OAWebBean webBean , BufferedReader in )
{
xxlearn.oracle.apps.fnd.server.LearnAMImpl am = (xxlearn.oracle.apps.fnd.server.LearnAMImpl)pageContext.getApplicationModule(webBean);
XxcusCsvFileBlobEOVOImpl vo = am.getXxcusCsvFileBlobEOVO1() ;
XxcusCsvFileBlobEOVORowImpl row = null;
try
{
//Open the CSV file for reading
String lineReader = "";
long t = 0;
String[] linetext;
while (((lineReader = in.readLine()) != null))
{
//Split the deliminated data and
if (lineReader.trim().length() > 0)
{
System.out.println("lineReader" + lineReader.length());
linetext = lineReader.split(",");
t++;
int lineLength = linetext.length;
System.out.println("line text length is : " + lineLength);
if(lineLength ==3)
{
row = (XxcusCsvFileBlobEOVORowImpl)vo.createRow();
Number fileID = am.getOADBTransaction().getSequenceValue("XXCUS_CSV_FILE_ID_S");
row.setFileId(fileID);
row.setOrgcode(linetext[0]);
row.setSegment(linetext[1]);
row.setStatus(linetext[2]);
}
for (int k = 0; k < lineLength; k++)
{
System.out.println(linetext[k]);
} //for
}//if
} //while
am.getOADBTransaction().commit();
}//try
catch (IOException e)
{
}
throw new OAException("Data Saved Successfully", OAException.INFORMATION) ;
}
Database Table Structure
-----------------------------------------------------------------------------------------
CREATE TABLE xxcus_csv_file_blob
(
file_id INTEGER
, status varchar2(100)
,segment varchar2(100)
,orgcode varchar2(10)
,creation_date DATE
,created_by NUMBER
,last_update_date DATE
,last_updated_by INTEGER
,last_update_login INTEGER
,CONSTRAINT xxcus_csv_file_id PRIMARY KEY (file_id)
) ;
create sequence XXCUS_CSV_FILE_ID_S ;
-----------------------------------------------------------------------------------------
PS: Above coding is not totally mine, i copied from the below blog
http://rajubandam.blogspot.in/2014/01/uploading-csv-file-into-data-base-table.html
No comments:
Post a Comment