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 Connecting to Excel thru JDBC 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 "Connecting to Excel thru JDBC" Watch "Connecting to Excel thru JDBC" New topic

Connecting to Excel thru JDBC

Farooq Ali
Ranch Hand

Joined: Sep 30, 2000
Posts: 43
hi guys...
Can anyone guide to how to connect to an excel file through JDBC-ODBC bridge.
I want to know what is written in the sql query instead of the tables
is this query right
"SELECT fruits from SHEET$1" where fruit is a column is sheet1
I know there are are a lot of post on this question in javaranch
can any one send the urls to those discussions....
thanks a lot
Mark Simms
Ranch Hand

Joined: Jul 20, 2000
Posts: 36
1) create a DSN that points to the excel (xls) file
2) apply this coding pattern usnig Sam$ as the sheet name:
import java.sql.*;
class JavaExcel
Connection con = DriverManager.getConnection("jdbc dbc:JavaExcel","","");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select Name,Marks from [Sam$]");
while (
catch (Exception e) {e.printStackTrace();}
public static void main(String[] args)
new JavaExcel();

I agree. Here's the link:
subject: Connecting to Excel thru JDBC
It's not a secret anymore!