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


Please Help Members By Posting Answers For Below Questions

Which interface is responsible for transaction management in jdbc?

606


List some new features available in jdbc 4.0?

634


What is the latest version of JDBC? What are the new features added in that?

710


What are the utilities of the callablestatement?

699


What is jdbc url for mysql?

741






Why hibernate is better than jdbc?

656


Which jdbc drivers will run your program?

666


What is sqlwarning?

720


When do we use execute method in java jdbc?

691


Explain some new features available in jdbc 4.0?

760


Which is best database for java?

701


How do you determine the sensitivity of the ResultSet object?

720


How you restrict a user to cut and paste from the html page using java programing?

629


How can I know when I reach the last record in a table, since JDBC doesn't provide an EOF method?

737


What is JDBC Savepoint? How to use it?

828