File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes accessdata using excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "accessdata using excel" Watch "accessdata using excel" New topic

accessdata using excel

Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
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 = "";
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 ( {
System.out.println(rs.getString("name") + " " + rs.getString("no"));

} catch (Exception e) {
} finally {
try {

} catch (SQLException e) {

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

name and no.



SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116

Take a look at Apache POI.

I agree. Here's the link:
subject: accessdata using excel
It's not a secret anymore!