Reputation: 43
I have been tasked with comparing data in an excel file (in .csv
format) to my companies oracle database in Java
. Once the data has been compared, I need to write if the data is the same or different to a new .csv
file.
I have written the read and write methods to access the excel file.
I do not know how to actually compare columns in excel to columns in the oracle database.
Here is the stringbuilder
given to me to actually select the data from the table.
//***********************************************************************
//SQL string builder
//***********************************************************************
StringBuilder sSQL = new StringBuilder("");
sSQL.append("SELECT * FROM NSA_AL.POLVEHICLE PV");
sSQL.append(" WHERE PV.VIN='?'");
sSQL.append(" AND PV.POLICYID='?'");
sSQL.append(" AND PV.SEGEFFDATE<=TO_DATE('06/10/2012 08:00','MM/DD/YYYY HH24:MI')");
sSQL.append(" AND PV.SEGEXPDATE>=TO_DATE('06/10/2012 08:00','MM/DD/YYYY HH24:MI')");
sSQL.append(" AND PV.SEGSTATUS=");
Any help would be appreciated.
Upvotes: 0
Views: 2321
Reputation: 24336
Create an object with a function called toCSV
.
public class MyCSVMapper
{
String[] fields = {"First","Second","Third"};
public String toCSV()
{
String formatted = "";
for(int i = 0; i < formatted.length;i++)
{
if(i == formatted.length-1)
{
formatted+=formatted[i];
break;
}
formatted+=formatted[i]+",";
}
return formatted;
}
}
Take this generated CSVfile and load it into Excel, you should be able to compare these files within the context of Excel.
Upvotes: 1
Reputation: 18458
It is better to read Oracle data using jdbc and excel data using api(say Apache POI) and do comparison. You can write/update excel file using Apache POI.
Upvotes: 0