....
Originally posted by Lakshmi:
Hi,
I got the solution for the query which i posted. With the following code we can read a XLS file. Considering the File as the Database with a single Table and the table name is the Name of the File. And the contents in the First row as the columns names, we read the file as if we are querying a Table.
1) First step before executing the code is to create a DSN for the XLS file.. In the Eg below the DSN I have created is "XLDSN".
2) TEST is the name of the XLS File. and Mind u the "$" sysmbol is mandatory after the file name in the select statement.
3) rs.getObject("subject").. In this statement subject is one of the columns in the first row of the XLS file.
Cheers,
Lakshmi.
/**************************************/
import java.sql.*;
import java.lang.*;
public class ReadXLS
{
public static void main(String args[])
{
Statement stmt=null;
Connection conn=null;
String sql="";
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc : odbc : XLDSN","","");
stmt=conn.createStatement();
sql="select * from [TEST$]";
rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println("The Subject name : " +
rs.getObject("subject"));
}
rs.close();
stmt.close();
conn.close();
rs=null;
stmt=null;
conn=null;
}
catch (Exception e)
{
System.err.println(e);
}
}
[This message has been edited by Lakshmi (edited July 18, 2000).]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Sun Certified Java Programmer
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions