Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I connect to an Excel spreadsheet file using jdbc?

0
Posted

How can I connect to an Excel spreadsheet file using jdbc?

0

Let’s say you have created the following Excel spreadsheet in a worksheet called Sheet1 (the default sheet name). And you’ve saved the file in c:\users.xls. USERID FIRST_NAME LAST_NAME abc a b xyz x y Since Excel comes with an ODBC driver, we’ll use the JDBC-ODBC bridge driver that comes packaged with Sun’s JDK to connect to our spreadsheet. In Excel, the name of the worksheet is the equivalent of the database table name, while the header names found on the first row of the worksheet is the equivalent of the table field names. Therefore, when accessing Excel via jdbc, it is very important to place your data with the headers starting at row 1. • Create a new ODBC Data Source using the Microsoft Excel Driver. Name the DSN “excel”, and have it point to c:\users.xls. • Type in the following code: Connection conn=null; Statement stmt=null; String sql=””; ResultSet rs=null; try { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); conn=DriverManager.getConnection(“jdbc:odbc:excel”,””,””); stmt=co

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123