Wednesday 6 June 2012

Dealing with Excel database

Ms-Excel is the confidential database used for representing financial information for generating balance shee


But in the some of the Industry requirements, we need to read the data from excel-sheet and store that data into secured data bases.

Steps for dealing with Excel database


1. open excel and ensure the sheet nos(ex:sheet1,sheet2,sheet3)
2. Enter the data by choosing in on of the excel sheet
            stno          name            add
             1              suresh        kerala
             2              srikanth      andhra
             3              frook         ooty
             4              raju            hyd

3. In which ever sheet we entered the data, rename the sheet no
    (right click of mouse----> choose rename) the renamed sheet no acts as table name

4. create dsn for excel 
     control panel---->driver do microsoft excel(*.xls)--->give datasource name(exe)---->click on select workbook---->select workbook in where you saved(excel sheet)---->ok---->ok.

5. Write java program


import java.sql.*;
class first
{
public static void main(String arg[]) throws Exception
{
sun.jdbc.odbc.JdbcOdbcDriver d=new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
System.out.println("Drivers are loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:exe");
System.out.println("Connection is established");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from [student$]");
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
System.out.println(s1+"       "+s2);
}
con.close();
}
}



No comments:

Post a Comment