wood burning stoves 2.0*
The moose likes JDBC and the fly likes how to access data in excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to access data in excel" Watch "how to access data in excel" New topic
Author

how to access data in excel

viswanath chennuru
Greenhorn

Joined: Aug 19, 2009
Posts: 3
hi all,
I am trying to access data that is present in MS excel and for that i have written the following program.The excel sheet name is "abc".

mport java.sql.*;


public class Main {
public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement stmt = DriverManager.getConnection("jdbc: odbc:abc").createStatement();
ResultSet rs = stmt.executeQuery("select * from [Sheet1$]");
while (rs.next()) {
String lname = rs.getString(1);
String fname = rs.getString(2);
int id = rs.getInt(3);
System.out.println(fname + " " + lname + " id : " + id);
}
rs.close();
stmt.close();
}
}

but when i am running it i am getting the following exception

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.gwtbook.client.Main.main(Main.java:9)

Can someone tell me what the problem is??
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Dear,
Did you set up your ODBC data source? if not
follow this :
http://www.corda.com/docsource/doc7/Manuals/install_admin/setting_up_the_example_odbc_data_source.htm

Regards,
Sahar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access data in excel
 
Similar Threads
error when i run the program
TNSAddress.SOException
Applet reading from Excel sheet
can't update database?
Applet Reading from Excel Sheet