3

I am using JDBC-ODBC DSN-less connection to connect to ms-excel file. I was able to query the excel file using query of form

SELECT * FROM [Sheet1$]

However this requires me to know the name of the Sheet in excel file (which may not always be Sheet1). Is there any way I can query the excel to always hit its 1st sheet?

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
Aditya Jain
  • 1,077
  • 1
  • 12
  • 25

1 Answers1

1

Use:

DatabaseMetaData meta = con.getMetaData();

where con is your connection. On meta object you can call:

getSchema();
getTables(null, null, "%", null); // thanks to AVD

Both of the methods return ResultSets on which you can iterate to see what's inside. There is no guarantee that getTables() method will return full data.

Maybe I quoted wrong methods, but I am sure you can find some in DatabaseMetaData class that will return what you need in case of excel.

user1581900
  • 3,680
  • 4
  • 18
  • 21