
Suppose there is folder in C:\fileupload which contains these two csv files:
file1.csv has 3 columns(VendorID,Name)
file2.csv has 2 columns(VendorID,address)///// here VendorID is corresponding to file1.csv
i want to retrive data from these two files and store in oracle database as:
VendorID,Name,Address
and plz be specific in telling me through java only Any help will be much appreciated.
Thanks

Here is a code that retrieves the column values from csv file and save it into database.
import java.io.*;
import java.sql.*;
import java.util.*;
import jxl.*;
import jxl.read.biff.BiffException;
class StoreCSVDataToDatabase
{
public static void main(String[] args) throws Exception
{
ArrayList<String> list1=new ArrayList<String>();
ArrayList<String> list2=new ArrayList<String>();
ArrayList<String> list3=new ArrayList<String>();
Cell rowData[] = null;
int rowCount = 0;
int columnCount = 0;
int totalSheet = 0;
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
Workbook workbook = Workbook.getWorkbook(new File("C:/data.csv"), ws);
Sheet s = workbook.getSheet(0);
rowCount = s.getRows();
columnCount = s.getColumns();
for(int i = 1; i < rowCount; i++){
rowData = s.getRow(i);
if(rowData[0].getContents().length() != 0){
for(int j = 0; j < columnCount ;j++){
switch(j){
case 0:
System.out.println("ID: "+rowData[j].getContents());
list1.add(rowData[j].getContents());
break;
case 1:
System.out.println("Name: "+rowData[j].getContents());
list2.add(rowData[j].getContents());
break;
case 2:
System.out.println("Address: "+rowData[j].getContents());
list3.add(rowData[j].getContents());
break;
}
}
}
}
workbook.close();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia","root", "root");
Statement st=conn.createStatement();
for(int i=0;i<list1.size();i++){
String id=list1.get(i).toString();
String name=list2.get(i).toString();
String address=list3.get(i).toString();
st.executeUpdate("insert into data(id,name,address) values('"+id+"','"+name+"','"+address+"')");
}
System.out.println("Data is successfully inserted into the database");
}
}
For the above code, you need jxl.jar and put it into the lib of jdk and apache tomcat.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.