how to upload excel into database using java? - java

hi
i am having one excel file which contains 15 columns and having 5000 recordes.
Now entering 5000 records manually into database is really a tough one.
instead i want to create a small java application which get input as excel file and just by clicking upload to database button it should be uploaded to DB.
any ideas? is there any jar?
please anybody guide me with example

You need a excel parser. The popular one is POI Spreadsheet. Another one is JExcelAPI.

If you're using MySQL you'll probably want to look at this: Import Excel Data into MySQL in 5 Easy Steps.
Otherwise checkout the Java Excel API or Apache POI to parse an Excel document. Then iterate over the cells and insert them into your database. See Getting Started with JDBC if you're not familiar with writing to a database. Search around online as well, there are all sorts of libraries and examples out there.
Without more details about what you're doing it's hard to make more than these general suggestions.

Related

What to use : Excel VS MySql/MongoDB [Java]

I am going to make a business application for my father to make GST(Goods and Services Tax) filing easier. I have the design ready and I am going to use JavaFX.
The user will enter the data in tableview and that data needs to be stored for future reference.
The tableview needs to be converted to an excel file (gonna use Apache POI). The excel file will be sent to a C.A who will file GST on my father's behalf.
The application will need to import/export data into/from the tableview and edit the data as necessary.
I have 2 options :
Store/retrieve data from MySQL to tableview, update it according to the user's will and later export the data into excel files for sending it to C.A.
Store/retrieve data from excel files to tableview, update it according to the user's will and send the excel file to C.A.
I am planning to expand the application into a complete Business software that can manage entire business.
What should I use?
Which one will be more efficient and why?
I hope I am able to convey my question (I ain't good at writing).
In my own opinion it is more efficient and have more posibilities to explotes the data using MySQL, because reading and writing an Excel file will take a lot of time and it is slower.
I'll answer my own question, since I have got the answer.
I'm going with SQLite for now as using csv or excel files is gonna consume a lot of resources (I tried it).
I am going to sync the .db file in drive using scripts from the application itself. MySQL is definitely better choice but I want to database to be used by 2 computers at a time (not in network) so I will have to pay for online database.
I will store the .db file and drive and will retrieve it whenever the application runs. In this way its going to be safe.

Adding data in Excel file without closing it

I am currently using Apache POI to enter data into Excel file. The only problem is I can not keep the file open if I have to append data to the same file. Are there any specific sample codes which would allow me to do so?
My basic requirement is to fetch Runtime data from a place (this I am able to do) and add it to the Excel sheet while the file is still open.
Any suggestions?
I don't think that this is possible without a C# addon or some kind of macro. You could write a simple C# addon for Excel that connects to your java programm and recieves the realtime data. The addon will write it to the spreadsheat then.

refreshing an excel sheet via java

I have to build and app that extracts stock exchange data from an excel sheet then save it
in a database. The problem is that the excel sheet obtains new data via a Bloomberg plug in.
To refresh the page, the user has to open the spread sheet and hit the refresh button on the plug in in excel. After a second the data is added to the sheet.
i have seen guides about getting or putting data to an excel sheet via java but am not sure how to open the sheet, trigger the update and get the data.
Maybe you can retrieve the data directly with Excel, by using Web Queries.
So basically, this feature allows you to get data from the web. You specify the URL, then you select which data on the page you want to import.
You can write these queries in VB as well (ask if you want more details on how to do it with VB).
http://office.microsoft.com/
It is not clear what you are trying to achieve. I understand that you only use the spreadsheet to get the data and save it to a database.
There are a few alternatives I can think of:
[dirty] create a scheduled task in Windows that opens the spreadsheet every x minutes / hours. In your workbook, create a Workbook_Open event that uses Application.OnTime to execute a macro to do what you need to do with the data after a few minutes (the time it takes for the data to update). This is error-prone and will probably fail from time to time.
[better] use something similar except that you get the data programmatically with the VBA Addin, populate the sheet from VBA and/or do what you need to do with the data. No need for Application.OnTime in that case. You can even automatically save/close the spreadsheet.
[better] Have your java code get the data and send it to your database. If users need the data in Excel, you can have Excel query the database when required.
Note: with a typical Bloomberg Terminal/Anywhere license, it is not permitted to save data on a different machine so the database would need to be located on the local PC. Other licenses have different terms.
I think you should look into using Bloomberg's API v3 to retrieve the data. You have access to any field which you see in FLDS on the Bloomberg terminal.

Automatically update database when new excel sheet is added in a folder

I need to write one java program which monitors a folder containing excel sheets (.xls format) . Once a new excel sheet is added I have to update the database in db2 and move the excel sheet to other place.
Please suggest
It sounds like you need to get notified if files appear in a directory. Java 7 has good support for this, see this article about the Watch Service API. The db2 part, well it isn't clear what you mean by "update", but likely you want to parse the content of the xls file and make some database updates. Apache POI is a good starting place for reading the content of the file into a Java process.

Is it possible using apache poi to load data from an open excel file that is constantly updating?

I have this Java program that uses apache poi to load data from an excel file.
Problem I'm facing is I can't seem to load data from the excel file that is constantly updating. I only get the initial data when I run my java program.
You have to reread the data from the excel file. POI makes a copy into java objects when it reads it, so any further changes won't get reflected in your Java code without rereading the file.
If you mean that you do reread the file but don't see the updates, then it could be that someone is making changes in excel but not saving them, so POI can't see them yet.
This Answer is referred from Fetch Data From Excel have a look at this answer for more details. Maybe this question is a duplicate of the above link or vice versa.
The problem is because the excel data is not saved. I was also dealing with the same problem and got up with a different solution which worked for me. I just created a macro in excel to save the excel workbook whenever it's cell values got changed. Now I got the excel file with up-to-date saved data which can be read through java code and can be used for other purposes.

Categories