code for reading data from excel sheet from java application

HaiI am in need of some code that can read data from MS Excel sheet from a java application.
[106 byte] By [SantuDeepua] at [2007-10-2 18:19:03]
# 1

> Hai

>

> I am in need of some code that can read data from MS

> Excel sheet from a java application.

You can read Microsoft Excel files from Java using the Sun JDBC-ODBC driver to read Excel files.

/*

make the excel available as a odbc source by adding a driver in the windows(os) enviornment.

*/

import java.sql.Connection;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.DriverManager;

public class ExcelReader

{

public static void main( String [] args )

{

Connection c = null;

Statement stmnt = null;

try

{

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

c = DriverManager.getConnection( "jdbc:odbc:qa-list", "", "" );

stmnt = c.createStatement();

String query = "select URL from [qas$] where Month='March' and Year=2000;";

ResultSet rs = stmnt.executeQuery( query );

System.out.println( "Found the following URLs for March 2000:" );

while( rs.next() )

{

System.out.println( rs.getString( "URL" ) );

}

}

catch( Exception e )

{

System.err.println( e );

}

finally

{

try

{

stmnt.close();

c.close();

}

catch( Exception e )

{

System.err.println( e );

}

}

}

}

/*

select URL from [qas$] where Month='March' and Year=2000;

Note that qas,the table name is the name of the worksheet with a $ appended to the end. You have to append the $ in order for the query to work. Why? Because. The brackets are there because $ is a reserved character in SQL.

*/

rohithtpa at 2007-7-13 19:39:29 > top of Java-index,Core,Core APIs...