give me a java code snippet to connect Microsoft excel
through.... I am trying alot... plz help me.

Answer Posted / n.gowtham raj

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:gowtham");
Statement st = con.createStatement
();
ResultSet rs = st.executeQuery
("select * from [Sheet1$]");

while(rs.next())
{
System.out.println
("USER ID:"+rs.getString("ID"));
}

rs.close();
st.close();
} catch (Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}

Step 1: goto control panel and select the Administrative
Tools and click the odbc driver.
Step 2: Then click the add button and select the microsoft
excel driver (".xls")
Step 3: then give the dsn name. (gowtham).
Step 4: then click the select workbook button and choose
the excel file then it work well.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is encrypted connection?

499


What is the purpose of jdbc resultset interface?

571


How can you know about drivers and database information ?

549


Why resultset is used in java?

505


What is jdbc connection interface?

518






What are the new features available in jdbc 4.0?

533


What is represented by the connection object?

527


Does JDBC support stored procedures?

560


Is there another way of dealing with the result set that could execute faster?

519


How do I load a database driver with JDBC 4.0 / Java 6?

556


What is executeupdate in java?

473


What is jdbc architecture?

516


What is difference between odbc and jdbc?

504


Why we use jdbc instead of odbc?

499


How do I find whether a parameter exists in the request object?

495