I scraped a website and fetch the data into the .CSV file. This process has been successfully executed and working properly. But, when I tried to fetch the data in the table of Oracle Sql Database it only brings the first row of the .CSV file and don't retrieve the other lines of the data. I am trying to retrieve the data of CSV file through SQLLoader written in create script. When I call any other CSV through that script it is working fine and brings all the data. But, this matter only comes in the file which has been created through the java program.
Java code is as follows.
public static void parsingHTML() throws Exception {
for (int i = 1; i <= 1; i++) {
tbodyElements = doc.getElementsByTag("tbody");
if (tbodyElements.isEmpty()) {
throw new Exception("Table is not found");
}
elements = tbodyElements.get(0).getElementsByTag("tr");
for (Element trElement : elements) {
trElement2 = trElement.getElementsByTag("tr");
tdElements = trElement.getElementsByTag("td");
File fold = new File("C:\\convertedCSV9.csv");
fold.delete();
File fnew = new File("C:\\convertedCSV9.csv");
FileWriter sb = new FileWriter(fnew, true);
for (Iterator<Element> it = tdElements.iterator(); it.hasNext();) {
Element tdElement1 = it.next();
final String content2 = tdElement1.text();
if (it.hasNext()) {
sb.append("\n");
}
for (Iterator<Element> it2 = trElement2.iterator(); it.hasNext();) {
Element tdElement2 = it.next();
final String content = tdElement2.text();
if (it2.hasNext()) {
sb.append(formatData(content));
sb.append(" , ");
}
if (!it.hasNext()) {
String content1 = content.replaceAll(",$", " ");
sb.append(formatData(content1));
it2.next();
}
}
System.out.println(sb.toString());
sb.flush();
sb.close();
}
System.out.println(sampleList.add(tdElements));
}
}
}
And Create Script is
-- Create table
create table TEST_EXCEL_OPEN_END_SMRY
(
fund_name VARCHAR2(150),
rating VARCHAR2(50),
validity_date VARCHAR2(50),
fund_nav VARCHAR2(50),
ytd VARCHAR2(50),
mtd VARCHAR2(50),
day_1 VARCHAR2(50),
days_15 VARCHAR2(50),
days_30 VARCHAR2(50),
days_90 VARCHAR2(50),
days_180 VARCHAR2(50),
days_270 VARCHAR2(50),
days_365 VARCHAR2(50)
)
organization external
(
type ORACLE_LOADER
default directory DIR_KSE
access parameters
(
RECORDS DELIMITED BY NEWLINE
badfile bad_dir:'revext%a_%p.bad'
logfile log_dir:'revext%a_%p.log'
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(
FUND_NAME,
RATING ,
VALIDITY_DATE ,
FUND_NAV ,
YTD ,
MTD ,
DAY_1 ,
DAYS_15 ,
DAYS_30 ,
DAYS_90 ,
DAYS_180,
DAYS_270,
DAYS_365
)
)
location (DIR_KSE:'convertedCSV9.csv')
)
reject limit UNLIMITED;
P.S: Path of the DIR_KSE is correct. I am also attaching the snapshot of CSV and Database result.

