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 to move the cursor in scrollable resultset ?
How do I insert/update records with some of the columns having NULL value?
Is jpa faster than jdbc?
What are the differences between setmaxrows(int) and setfetchsize(int)?
What is a jdbc connection?
How many locking systems are there in jdbc?
What is jdbc and why is it required?
Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?
Explain the steps in writing a java program using jdbc?
What are the benefits of PreparedStatement over Statement?
What do you mean by batch processing in jdbc?
How can I get information about foreign keys used in a table?
Which package is used for jdbc application?
What is the JDBC?
What is namedparameterjdbctemplate?