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();
}
}
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
Posted by Inampudi | 5:37 AM
where should we give the path of the excel sheet
Posted by Aakash | 11:27 PM