import .xls files to mysql in java servlet - java

I have a folder of 300+ xls files. The structure of this files is the same, but data is different. So I need to import this data to mysql table using servlets.
I think there are few stages:
Load a folder with files to server
Convert files to .csv
Import files one by one to mysql
But how can I implement this mechanism technically using servlets?
Thanks

First convert Xls to csv using this:
http://permalink.gmane.org/gmane.comp.jakarta.poi.user/14301
Then Import the csv using this:
http://www.javalobby.org/java/forums/t53674.html

using apache poi you can easily read any number of xls file.
link :http://poi.apache.org/
To insert it into database it is not required to convert it into .csv. You can read each cell of each file .Since each file's structure is same a List of DTO formed by storing all value of you excel sheet can be directly inserted into database.
You can get started at http://poi.apache.org/spreadsheet/quick-guide.html
Best of Luck

Related

How to import an excel file into database without giving "create table ... " script using java

I have to create a library that will be used by others to import data from an excel sheet into a database.
The user will only give the name of excel file and the database connection.
The library has to build a create table script and insert the data. The name of the table can be the same as the excel file name.
What is the best solution in java? Is there an api that does this?
Thanks.
Below is what will do in this sense.
First, read and parse the excel data. jxl or poi library can do this.
If we can't read or parse excel, break flow
When parsed successfully, create the corresponding table by using the jdbc api or something like that. The table structure based on the excel sheet columns.
Then batch insert the parsed excel data into database.

Removing data from multiple excel files

I have two excel files. There is some common data in both the files. I want to get a new excel file which only has non redundant data. I am reading data from excel files using apace POI (Java). Any help on the algorithm that can be used to remove the redundant data (since there are more than 10,000 rows in each excel file). Thanks.
copy all the data in HashSet(). and write it in another file.

Creating multiple sheets in CSV file

I am using superCSV to write data in csv format in my code. Its working absolutely fine and very efficiently , but now my requirement changed . I need to write multiple sheets in single xls file which is very time consuming task. So is there is any way in supercsv by which i can write multiple sheet data in single csv file and will send it to client, so that when client open this csv file in MS-Excel, he can see multiple sheets rather than me generating the excel file with with multiple sheets and sending it to client.
Thanks
CSV is a very simple format, and does not have the concept of a "sheet".
So, no, it's not possible directly.
The only thing that I can suggest is to send multiple csv files to the client, perhaps as a .zip file, and have the client unizp it and import one sheet at a time into Excel.
If you need it to open directly in the browser, you'll need to go with an xls file.
Take a look at the api here.
http://supercsv.sourceforge.net/apidocs/index.html
I'm not familiar SuperCsv please don't beat me up too bad if I'm wrong...
Can't you just set CsvPreference to EXCEL

How to get the values from DB and store it in a existing excel file using java?

I want to store the values from the database to an existing excel file. For example if the file is stored in C: data.xls. I want the data from db table to be stored in that.
I will mention the column name in the excel file itself.
Please help me to do this.
Use JDBC API to read/fetch result from the MySql database and jExcelAPI or Apache POI (recommended) to write/update excel document.
Writing to a CSV file is probably the easiest way to do this. CSV files can be opened up in Excel, but cannot have any text formatting. See the CSV Wikipedia article for more details on the format.
If you would rather use an XLS or XLSX format, consider using Apache POI, as the formats of those file types (particularly XLS) is quite complicated to write to manually.
If you are going for a CSV file, you need only open the file, and begin putting rows, one per line, with commas in between values. It's very simple, and works with a variety of software.

Is there any API that takes an Excel file and converts it to a CSV file using Java?

I have 200,000 or more records in an Excel file. If I tried to read records row by row and create a CSV file it's very costly as well as time consuming. Is there any API that can help me with that?
There are several frameworks out there, if you have a look.
For example, you can try:
Apache POI (example)
JExcel (example)
This seems to be the same question as How to import an Excel file into MySQL using ODBC in Java?
What has changed? If you want to write to a CSV file you should use a CSV library such as OpenCSV: http://opencsv.sourceforge.net/

Categories

Resources