0
votes

I want to read my cell values (in Excel file) using Java. In the process I am using ODBC to give the Excel file as my data source. I wrote the user, password, URL and all properties code in a separate .properties file, for my Java program to read and connect to the ODBC. It works fine when I run it on my local machine, but fails to when I run it on server. The error I receive is:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The server is a 64-bit machine working on Windows 2012. I checked my admin tools in control panel (of server). It has two ODBC's, one for 32-bit, the other 64-bit.

What's the reason for my code running only on my local machine and not on the server?

Is it because of there being two tools, and the program being confused on which one to look for?

myDB=jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx)};DBQ=c:/data.xls;READONLY=true;DriverID=22;

this is the code I wrote in the .properties file. user & pwd fields are blank.

Is there something I am missing or is it something else?

1

1 Answers

1
votes

I think that the best bet here is to create an ODBC DSN from the control panel and then try to connect through it :

java.sql.Connection c = java.sql.DriverManager.getConnection( "jdbc:odbc:exsh", "", "" );

Whereas “exsh” is the name of DSN which points at a spreadsheet file which is going to be processed.

Without the DSN the connection string should be :

"jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=c:/data.xls"

Remember that since you are on a 64bit system you probably need to install the 64-Bit OLEDB Provider for ODBC (MSDASQL) .