• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

accessdata using excel

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

How to access data from excel sheet.

I have created a datasource and pointed that to excel sheet.

But when i try to access that i gives me error stating that it didnot find the name of excel sheet.

Here is my code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Date;


public class TestExcelData {

public static Connection getConnection() throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:excelDB";
String username = "";
String password = "";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}

public static void main(String args[]) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = getConnection();
stmt = conn.createStatement();
String excelQuery = "select * from Book1";
rs = stmt.executeQuery(excelQuery);

while (rs.next()) {
System.out.println(rs.getString("name") + " " + rs.getString("no"));

}
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
try {
rs.close();
stmt.close();
conn.close();

} catch (SQLException e) {
e.printStackTrace();
}
}
}
}


my excel sheet name is book1.xsl it has two columns

name and no.

thanks

Jetendra
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Take a look at Apache POI.

John
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic