1.

How to Connect to an Excel Spreadsheet using JDBC in Java?

Answer»

Follow the steps below

First setup the new ODBC datasource. Goto Administrative Tools−>Data Sources (ODBC)−>System DSN tab−>Add−>Driver do Microsoft Excel(*.xls)−>Finish. Now give the Data Source Name (SampleExcel) & Description. Next, click Select Workbook and point to your excel sheet.

In the code make to following code additions

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn = DriverManager.getConnection("jdbcodbcSampleExcel","","");stmt = conn.createStatement();sql = "select * from [Sheet1$]";rs=stmt.executeQuery(sql);

Where Sheet1 is the excel sheet name.



Discussion

No Comment Found