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
What are the ddl statements?
How does jdbc driver work?
How can you use preparedstatement in jdbc?
What are 4 drivers available in JDBC? At what situation are four of the drivers used?
What is a rollback in jdbc?
How can I instantiate and load a new CachedRowSet object from a non-JDBC source?
How java can be connected to a database?
How does jdbc work?
What is a java driver?
What are the new features available in jdbc 4.0?
What is a jdbc connection pool?
Does jpa use jdbc?
What is meant by jdbc and odbc?
What is the benefit of having jdbcrowset implementation?
Which type of JDBC driver is the fastest one?