3

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

1
  • 2
    Your "preference" not to depend on external packages seems misguided. After all, depending on an ODBC driver is significantly more fragile (depends on running on Windows, depends on the Excel ODBC driver being installed) Commented Oct 30, 2009 at 22:07

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

2

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.

2 Comments

Thorbjørn: This should be posted in the comments section.
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.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.