Home Answers Viewqa Java-Beginners retrieve multiple columns values from multiple csv files in java

 
 


lata
retrieve multiple columns values from multiple csv files in java
1 Answer(s)      6 months and 2 days ago
Posted in : Java Beginners

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

View Answers

November 22, 2012 at 12:41 PM


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.









Related Pages:
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  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
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
retrieve multiple attribute values
XML retrieve multiple attribute values  Hello All Am a beginner...; What I would like is to retrieve both the attribute values of process... using Java. Thanks in advance
how to sort multiple key columns in CSV file - Java Beginners
how to sort multiple key columns in CSV file  Hi Any one can assist how to sort the multiple key columns in CSV file? Any example will be appreciated. Thanks
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row  Hai, I need... or .txt) file and get the values from that file and store them into database
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
Mysql Alter Add Multiple Columns
The Tutorial illustrate an example from 'Mysql Alter Add Multiple Columns'. To understand... Mysql Alter Add Multiple Columns       Mysql Alter Add Multiple Columns is used to modify the table
Mysql Alter Multiple Columns
illustrate an example from 'Mysql Alter Multiple Columns'. To grasp this example... Mysql Alter Multiple Columns       Mysql Alter Multiple Columns is used to modify the table definition
Retrieve multiple data from database into Table.....
Retrieve multiple data from database into Table.....   hi........... I want to Retrieve multiple data from database into Table but i am not able to.... i am only able to retrieve one value not more than that. means in my
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... take one record the values are source is chennai, destination is kanchipuram
Retriving multiple values of checkboxes in struts
Retriving multiple values of checkboxes in struts  how to retrive multiple values of checkboxes of jsp in action class   JSP Retrieve checkbox values 1)checkbox.jsp: <html> <body> <form method="post
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information.... We have to find the students according to particular school from all the files
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Renaming multiple files
Renaming multiple files  Hi, I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. .... Now I wanted to rename these files as: 1RohitBBorse.mp4
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...); } i want to convert the data from inputStream into Zip Stream and so
SQL Alter Table Add Multiple Columns
SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL... Add Multiple Columns. The SQL Query create a table 'Stu_Table' with table
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere..."; /** * This is returning a single Object, which contains * multiple values
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere..."; /** * This is returning a single Object, which contains * multiple values
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com...://www.roseindia.net/tutorial/java/core/files/fileconcatenation.html   
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public...??? 1)first -.java file package pack; public class admin { private int Book_id
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public...??? 1)first -.java file package pack; public class admin { private int Book_id
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public...??? 1)first -.java file package pack; public class admin { private int Book_id
How to pass multiple values from a servlet to JSP?
How to pass multiple values from a servlet to JSP?  hi, I want to pass multiple values form a servlet to JSP. Hw do i do that? I am able to send one value at a time without any prb, but I am unable to carry multiple (from two
How to carry multiple values from a Servlet to a JSP?
How to carry multiple values from a Servlet to a JSP?  By using...). ----response.sendRedirect("index.jsp?uname="+username);---- But I want multiple values needs to be carried from my servlet to a JSP. How do I do
Export Database table to CSV File
to retrieve data from database and save it to CSV File. The Comma-separated values, better knows as CSV is having a delimited data format. It has field/columns... similar to text files. Exporting or writing data to csv file is exactly same
SQL Alter Table Add Multiple Columns
SQL Alter Table Add Multiple Columns       Alter Table Add Multiple Columns in SQL... Add Multiple Columns. The SQL Query create a table 'Stu_Table
how to get multiple hyperlink values from a table column to another jsp file?
how to get multiple hyperlink values from a table column to another jsp file?  dear sir: this is what i'm trying to do, i have 3 JSP files. first... file named "dbtable" will get the parameter from "index" and search
Retrieve values from database using views
Retrieve values from database using views  hi......... I have a huge... the columns which are required. As my front end is java swings i want to retrieve data from that created views and display on form . I am trying to do so but its
Uploading the multiple files
. For uploading the multiple files at a time, first create a table as per required...; <HTML> <HEAD> <TITLE> Multiple Files Upload </TITLE>...="#FFFFFF"> <tr> <td><strong>Multiple Files
Mysql Multiple Date Insert
illustrate an example from 'Mysql Multiple Column Insert'.To understand... Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert
Mysql Multiple Date Insert
illustrate an example from 'Mysql Multiple Column Insert'. To understand an example... Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert
how to store multiple values from drop down in database where i am using java struts 1.3
how to store multiple values from drop down in database where i am using java... is displaying.. i need code in java so that it takes multiple values... where i have to select multiple keyskills. but it is taking only one valuee.. i
Copy multiple files
Copy multiple files        In this section, you will learn how the data of multiple files.... For copping the data of multiple file, you need all files in a specified directory where
multiple select values
multiple select values   can you provide an example for multiple select values for html:select tag
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
display multiple image file or pdf file in multiple column of a row from server or database
in a particular format i.e I have to display more than one files in multiple columns in a single row..Suppose I have to display two files in a row then after...display multiple image file or pdf file in multiple column of a row from server
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
i am getting multiple values in listbox
i am getting multiple values in listbox   hi sir, i am using msaccess 2007.my query is look like this. select distinct a.name,b.fee from table1 a,table2 b where a.stuno=b.stuno and b.recdate in(select max(recdate) from

Ask Questions?

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.