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.
I am using Java in NetBeans to develop a program where i need to retrieve data from the few list of database file which is in 'dbf' format. I normally open the 'dbf' file with Microsoft Excel then import to Microsoft Access but this time i need all the process happen inside the code and will it possible to use query to get the data as well ?
IMHO the best way is to import DBF tables into SQL database (H2, SQLite, PostgreSQL) and do any queries you need. Check this library github.com/Yasas/xbase4j and/or contact me for examples.
I want to import an Excel file into a MySQL database using an ODBC driver. Does Java support this technique? If yes, please guide me on how to implement this.
You can read an Excel file in Java using the Apache POI library: http://poi.apache.org/
There are some code samples on their howto page which will tell you how to read an Excel file: http://poi.apache.org/spreadsheet/how-to.html
To store the data it would be better for you to use the JDBC driver for MySQL rather than ODBC since ODBC relies on native libraries. You can get the connector here: http://www.mysql.com/products/connector/
If you absolutely must use ODBC, then you can see how to do that here: http://download.oracle.com/javase/1.5.0/docs/guide/jdbc/bridge.html
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
I am having a database in .dbf (FoxPro) format.
How to retrieve data from FoxPro using Java?
If the data can be migrated to MySQL, How to do the conversion?
Taking the data to intermediate formats seems flawed as there are limitation with memo fields and CSV or Excel files.
If you are interested in a more direct approach you could consider something like "VFP2MySQL Data Upload program" or "Stru2MySQL_2", both written by Visual FoxPro developers. Search for them on this download page:
http://leafe.com/dls/vfp
DB-Convert (http://dbconvert.com/convert-foxpro-to-mysql-sync.php) is a commercial product that you might find helpful.
Rick Schummer, VFP MVP
You can use XBaseJ to access (and even modify write) data from FoxPro databases directly from Java with simple API.
This would allow you to have the two applications (the old FoxPro and the new Java one) side by side by constantly synchronizing the data until the new application is ready to replace the old one (e.g. many times the customers still hang on and trust more their old application for a while).
Do you have a copy of FoxPro? You can save the database as an HTML file, if you want. Then, from HTML, you can save to any format you want. I recently did this to save a FoxPro table as an Excel spreadsheet (not that I'd suggest using that for your Java code).
If you plan on using Java, once you have access to the data, why not use one of Java's native storage types?
I worked on the same project once long back where the project had be done with FoxPro and then we migrated that project to Java with MySQL.
We had the data in Excel sheets or .txt files, so we created tables as exact replica of the FoxPro data and transferred the data from the Excel/CSV /txt to MySQL using the Import data feature.
Once we did this, I think further you can take care from MySQL Data.
But remember work will take some time, and we need to be patient.
I suppose doing a CSV export of your FoxPro data and then writing a little Java programme that takes the CSV as input is your best bet. Writing a programme that both connects to FoxPro and MySQL in Java is needlessly complicated, you are doing a one time migration.
By the way PHP could do an excellent job at inserting the data into MySQL too. The main thing is that you get your data in the MySQL schema, so you can use it with your new application (which I assume is in Java.)
Two steps: DBF => CSV and the CSV => MySQL.
To convert DBF(Foxpro tables) to CSV the below link helps a lot
http://1stopit.blogspot.com/2009/06/dbf-to-mysql-conversion-on-windows.html
CSV => MySQL
MySQL itself supports CSV import option (or) to read csv file this link helps
http://www.csvreader.com/java_csv.php
I read the CSV file using Java CsvReader and inserted the records through program. For that i used PreparedSatement with Batch the below link gives samples for that
http://www.codeweblog.com/switch-to-jdbc-oracle-many-data-insert/