« Home | Redirect output, error report to files instead of ... » | Assertions in java » | Program to copy a folder in java » | java.net.BindException: Address already in use: JV... » | java.lang.UnsupportedClassVersionError: » | Merge Sort » | Insertion Sort » | Selection Sort » | Program to Implement Quick Sort » | Bubble Sort » 

Wednesday, September 12, 2007 

Program to read excel sheet Using Java program

//program to read an excel sheet Using Java program

import java.io.*;
import java.util.*;
import java.sql.*;

public class TestExcel {

Connection c;
Statement stmnt;

public void Read_Excel()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

c = DriverManager.getConnection("jdbc:odbc:abc","",""); // abc is the DSN name
stmnt = c.createStatement();

String gh = "select * from [Offshore$]"; //Offshore being the name of the sheet in excel sheet

ResultSet rs = stmnt.executeQuery(gh);

while(rs.next())

{

System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));// for displaying the three rows present in the excel sheet
}

}catch(Exception e)

{
System.out.println(""+e.toString());
}
finally

{
try

{
stmnt.close();
c.close();
}
catch( Exception e )
{
System.err.println( e );
}
}

public static void main(String[] args)
{
new TestExcel().Read_Excel();
}
}

where should i give the path of the excel sheet

where should we give the path of the excel sheet

Post a Comment

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com