Click on Administrative tool
Click Oc)n DataSource (ODB
Click on Add button
Select MicrosoftExcel Driver (*.xls) from the Create new Data source dialog
box, and click on Finish button
Enter dsn name(ex: rajdsn)
Selct workWork book button
• enter
Click ok,ok,ok
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

/*step1: create the data in excel sheet, and save (same folder).
here i created...
•

public static Connection prepareConnection()throws
SQLException, ClassNotFoundException {

•
•
•
•
•
•
•
•

/*
D:jdbcpr...
Get excelsheet
Get excelsheet
Get excelsheet
Get excelsheet
Upcoming SlideShare
Loading in …5
×

Get excelsheet

358 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
358
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Get excelsheet

  1. 1. Click on Administrative tool
  2. 2. Click Oc)n DataSource (ODB
  3. 3. Click on Add button
  4. 4. Select MicrosoftExcel Driver (*.xls) from the Create new Data source dialog box, and click on Finish button
  5. 5. Enter dsn name(ex: rajdsn)
  6. 6. Selct workWork book button • enter
  7. 7. Click ok,ok,ok
  8. 8. • • • • • • • • • • • • • • • • • • • • • /*step1: create the data in excel sheet, and save (same folder). here i created: id, ename sal click->start->control panel->select administrative tool and then Data Sources (ODBC), TO OPEN ODBC Data Source Administrator dialog box */ import java.sql.*; public class GetExcelSheet { public static void main(String args[])throws SQLException, ClassNotFoundException { Connection con=prepareConnection(); Statement st=con.createStatement(); String query = "select * from [Sheet1$]"; ResultSet rs=st.executeQuery(query); System.out.println ("idt enametsal:"); while (rs.next()){ System.out.print (rs.getInt(1)+ "t"); System.out.print(rs.getString("ename")+ "t"); System.out.println (rs.getDouble("sal")); }//while }//main
  9. 9. • public static Connection prepareConnection()throws SQLException, ClassNotFoundException { • • • • • • • • /* D:jdbcprogwed>javac GetExcelSheet.java • • D:jdbcprogwed>set classpath=D:softwaresMySQLnewmysql-connector-java-5.1.1 8-bin.jar;.; • • D:jdbcprogwed>java GetExcelSheet */ String driverClassName="sun.jdbc.odbc.JdbcOdbcDriver"; String url="jdbc:odbc:rajdsn"; Class.forName(driverClassName); return DriverManager.getConnection(url); }//prepareConnection }//class

×