give me a java code snippet to connect Microsoft excel
through.... I am trying alot... plz help me.
Answer Posted / vijay
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
public class EmployeeReader1 {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager
.getConnection
("jdbc:odbc:friends_exl");
Statement st = con.createStatement
();
ResultSet rs = st.executeQuery
("Select * from [Sheet1$]");
ResultSetMetaData rsmd =
rs.getMetaData();
int numberOfColumns =
rsmd.getColumnCount();
System.out.println("No of cols " +
numberOfColumns);
while (rs.next()) {
for (int i = 1; i <=
numberOfColumns; i++) {
if (i > 1)
System.out.print(", ");
String columnValue
= rs.getString(i);
System.out.print
(columnValue);
}
System.out.println("");
}
rs.close();
st.close();
} catch (Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
How does jdbc driver work?
If you are truncated using JDBC, how can you that how much data is truncated?
How can I create a custom RowSetMetaData object from scratch?
What is odbc. how is it related to sql cli?
what happen if we set JDBC string to NULL?
How to set NULL values in JDBC PreparedStatement?
What do you mean by two phase commits?
Why do I get UnsatisfiedLinkError when I try to use my JDBC driver?
Is jpa faster than jdbc?
How do I write Greek ( or other non-ASCII/8859-1 ) characters to a database?
DB2 Universal claims to support JDBC 2.0, But I can only get JDBC 1.0 functionality. What can I do?
What is the JDBC syntax for using a literal or variable in a standard Statement?
Why is jdbc needed?
What is the role of the jdbc drivermanager class?
How do you determine the sensitivity of the ResultSet object?