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 does connection pooling mean ?

0 Answers  


What is a Connection?

1 Answers  


What are restrictions on triggers?

0 Answers  


How can I create a custom RowSetMetaData object from scratch?

0 Answers  


What is <discriminator > in Hibernate? How exactly inheritance of Object to Tables can be done? What is the benefits of discriminator?

1 Answers   AppLabs,






Is it possible to connect to multiple databases simultaneously? Using single statement can one update or extract data from multiple databases?

0 Answers  


How can we execute stored procedures?

0 Answers  


Does jdbctemplate close connection?

0 Answers  


What does adapter class provide?

0 Answers  


Explain about DSN?

0 Answers   Infosys,


What is the return type of class.forname() method?

0 Answers  


What does the jdbc resultsetmetadata interface?

0 Answers  


Categories