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

Answers were Sorted based on User's Feedback



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

Answer / sushant

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String myDB = "jdbc:odbc:Driver={Microsoft Excel Driver
(*.xls)};DBQ=c:/java/scratch/jdbc_test.xls;"
+ "DriverID=22;READONLY=false";
Connection conn = DriverManager.getConnection(myDB, "", "");

Is This Answer Correct ?    19 Yes 6 No

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

Answer / m.gangadhar

hi create DSN for Microsoft Excel(.xsl) in
controlpanel/administrativetools/datasources

after that write normal code for driver class and getting
connection Object.

Is This Answer Correct ?    10 Yes 4 No

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

Answer / r.salimulla baba

import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Connect extends HttpServlet
{
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con=null;
Statement st=null;
PreparedStatement pst=null;
ResultSet rs;
try
{
Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection
("jdbc:odbc:Std","","");
st=con.createStatement();
rs=st.executeQuery("select * from
[ExcelSheetName$]");
while(rs.next())
{
out.println(rs.getString
(1));
out.println(rs.getString
(2));
out.println(rs.getString
(3));
}
}
catch(Exception e)
{
System.out.println("Errr :"+e);
}
}
}

Is This Answer Correct ?    15 Yes 9 No

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

Answer / shailendra

Use Apache POI. They have provided all the api, for
creating, updating, writing.

http://poi.apache.org/hssf/quick-guide.html

Is This Answer Correct ?    10 Yes 8 No

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

Answer / 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

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

Answer / amar

import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Connect extends HttpServlet
{
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con=null;
Statement st=null;
PreparedStatement pst=null;
ResultSet rs;
try
{
Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection
("jdbc:odbc:Std","","");
st=con.createStatement();
rs=st.executeQuery("select * from
[ExcelSheetName$]");
while(rs.next())
{
out.println(rs.getString
(1));
out.println(rs.getString
(2));
out.println(rs.getString
(3));
}
}
catch(Exception e)
{
System.out.println("Errr :"+e);
}
}
}

Is This Answer Correct ?    4 Yes 4 No

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

Answer / 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

More JDBC Interview Questions

What are four types of JDBC driver?

0 Answers  


Why is jdbc used?

0 Answers  


Explain creation of statement object with connection method create method with help of an example.

0 Answers  


What is de-normalization?

1 Answers  


Which interface handles transaction management in jdbc?

0 Answers  






Is the JDBC-ODBC Bridge multi-threaded?

2 Answers   Wipro,


Which is better odbc or jdbc?

0 Answers  


What is 2 phase commit?

0 Answers  


What are the conditions applies to varchar variable, when using in procedures?

0 Answers  


Where jdbc drivermanager class is used?

0 Answers  


Does jdbc require oracle client?

0 Answers  


Different statements in JDBC?

3 Answers  


Categories