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
Why we use jdbc instead of odbc?
How do I load a database driver with JDBC 4.0 / Java 6?
What causes no suitable driver error?
Which jdbc driver is the fastest driver?
How to move the cursor in scrollable resultset ?
What is jdbc odbc bridge?
any one can explain about policy file rule? when i connect database with applet then ther is no compile time error but the run time error is occureed.i.e access is denied.policy file rule is related to this problem.
What is jdbc connection string?
What are the considerations for deciding on transaction boundaries?
What are the different types of statements in jdbc?
Which is best database for java?
How do I insert/update records with some of the columns having NULL value?
How can we move the cursor in a scrollable result set?
What are the components of jdbc?
How can I use the JDBC API to access a desktop database like Microsoft Access over the network?