File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Reading .xls(Excel file) with JDBC (error-SQL exception) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Reading .xls(Excel file) with JDBC (error-SQL exception)" Watch "Reading .xls(Excel file) with JDBC (error-SQL exception)" New topic

Reading .xls(Excel file) with JDBC (error-SQL exception)

abin awale

Joined: Dec 23, 2008
Posts: 7
Hi everyone,

I am working on accessing .xls(Excel file) from JDBC.

I am trying example from:from here

In that example:
c = DriverManager.getConnection( "jdbc: odbc:qa-list", "", "" );
In my case:
c = DriverManager.getConnection( "jdbc: odbc:TeamList", "", "" );

In that example:
String query = "select URL from [qas$] where Month='March' and Year=2000;";

In my case:
String query = "select Name from [TestWithJavaForExcelSheet$] where Proff='programmer';";

I am getting error:
java.sql.SQLException: [Microsoft][ODBC Excel Driver] 'TestWithJavaForExcelSheet$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

-> i have tried with TestWithJavaForExcelSheet (without $ sign/with $ sign)
and also I have done the configuration as shown in the link

Can anyone suggest me where I am missing ? Or where is the error.


Here is my code:

--> I even tried with short name like: test$... i.e my filename test.xls, but still giving same error

Thanks in advance,
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
JDBC isn't the appropriate API to interact with a spreadsheet. JDBC is intented to interact with a database. Besides, the ODBC bridge driver is almost the worst JDBC driver on the world.

To interact with spreadsheets, better use the appropriate API's for that. Commonly used ones are Apache POI HSSF/XSSF and Andy Khan's JExcelAPI. Information, documentation, tutorials/guides and examples are available at their homepages. Good luck.
abin awale

Joined: Dec 23, 2008
Posts: 7
Ya thats true, Apache POI and JExcelAPI might be the best one for .xls or .doc files.....I was just trying this for the first time, so came across that tutorial..

Thanks anyway for the suggestion,
kalaiselvi Bhalerao

Joined: Aug 19, 2011
Posts: 9
Dear Abin,

I want to know if you have explored Java with Excel. if yes, pl give me some idea about the website or books you refered I need to develop a small project by connecting java and excel.
Also pl let me know which is the best way to connect with excel JDBC or Jexcel API.
Thanks in advance.

Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
>Also pl let me know which is the best way to connect with excel JDBC or Jexcel API.
Apache POI should be the powerest api for Excel.
HXTT Excel is a commerical Excel JDBC solution.

I agree. Here's the link:
subject: Reading .xls(Excel file) with JDBC (error-SQL exception)
It's not a secret anymore!