tags:

views:

426

answers:

4

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

A: 

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.

Mike Sickler
best answer, thanx alot! I got my problem solved :D
evilReiko
gret. Can you mark me correct?
Mike Sickler
A: 

I made a small application which read in an Excel sheet in to a JTable model very quickly. I think you should reconsider your usage of external libraries.

Thorbjørn Ravn Andersen
Thorbjørn: This should be posted in the comments section.
OscarRyz
No, my recommendation is for him to use the JExcelAPI library to read his file. This will be platform independent and self-contained which ODBC isn't.
Thorbjørn Ravn Andersen
+2  A: 

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.

JimSizzle
good answer! I wish I could give you a vote-up
evilReiko
A: 

If you want to just read in the data, converting the XLS file to a CSV file format would be the best way.

monksy