File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "Connecting to Excel thru JDBC" Watch "Connecting to Excel thru JDBC" New topic
Author

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
Farooq
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
{
JavaExcel()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:JavaExcel","","");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select Name,Marks from [Sam$]");
while (rs.next())
{
System.out.println(rs.getString("Name"));
System.out.println(rs.getInt("Marks"));
System.out.println("-------");
}
}
catch (Exception e) {e.printStackTrace();}
}
public static void main(String[] args)
{
new JavaExcel();
}
}

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to Excel thru JDBC
 
Similar Threads
MS EXCEL Connect
excel worksheet as an odbc data source
JDBC
Transfer Excel Sheet information to database
JDBC Excel Metadata