Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Excel file (.xls) in Java

Tags:

java

excel

I want to read text from excel file in J2SE using NetBeans. I found an article here about using Apache POI and JExcelApi, but I'd prefer not depending on external packages. if possible, using only Java built-in packages.

This almost worked, but it gives me an exception error:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Do I need to install some ODBC driver (if so, which driver and how to install)? What's the simplest way to solve this? please help, thanks in advance

like image 826
evilReiko Avatar asked May 23 '26 14:05

evilReiko


2 Answers

To summarize what was said already, accessing excel data from Java can be done via a two-step-process:
1) Set up the excel file as an ODBC data source.
2) Use the JDBC-ODBC bridge to access the excel data, using the standard JDBC api.

It sounds like you may have two problems:
1) The ODBC data source may not be set up, hence the "data source not found" error.
2) The jar for the JDBC-ODBC bridge driver may not be in your classpath, hence the "no driver specified". Google around for it. It's not hard to find.

like image 54
JimSizzle Avatar answered May 25 '26 02:05

JimSizzle


You need to setup an ODBC driver that points to your Excel spreadsheet as a datasource. You can either create one using the Windows ODBC manager and reference it, or create it on the spot using the code here, at your same tutorial site.

like image 35
Mike Sickler Avatar answered May 25 '26 02:05

Mike Sickler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!