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 steps to connect to the database in java?
What is a statement?
How we store procedure in oralce for callable statements in jdbc
Expalin the method of calling a stored procedure from jdbc.
What is sqlwarning?
What is the advantage of namedparameterjdbctemplate?
When do we use execute method in java jdbc?
What is the return type of class.forname() method?
Explain how data flows from view to db and reverse
What is jdbc vs odbc?
What is use of connection pooling?
Explain creation of statement object with connection method create method with help of an example.
What are the differences between resultset and rowset?
Which jdbc drivers will run your program?
How can I determine where a given table is referenced via foreign keys?