samar
connect jdbc to an Excel spreadsheet
1 Answer(s)      4 years and 7 months ago
Posted in : JDBC

hello,

How can I connect to an Excel spreadsheet file using jdbc?

Advertisement
View Answers

October 26, 2010 at 11:14 AM


Hello Friend,

Follow these steps:

  1. Open Data Sources (Start->Settings->Control Panel->Administrative Tool->Data Sources(ODBC)
  2. Open User DSN tab
  3. Add a user DSN
  4. Select Microsoft Excel Driver(*.xls)
  5. Select work book or excel file and Create the DSN name (e.g excel)
  6. Click "Ok" and restart your compiler.
  7. Compile the following java code:

import java.sql.*;

public class JDBCExcel { public static void main(String args[]) { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:excel","", ""); Statement st = conn.createStatement(); String query = "select * from [Excel sheet$]"; ResultSet rs = st.executeQuery(query); while(rs.next()){ System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)); } } catch(Exception e){} } }

Note: 'Excel sheet' is the sheet name of the selected excel file in the query.

Thanks










Related Tutorials/Questions & Answers:
connect jdbc to an Excel spreadsheet
connect jdbc to an Excel spreadsheet  hello, How can I connect to an Excel spreadsheet file using jdbc?   Hello Friend, Follow..."); Connection conn = DriverManager.getConnection("jdbc:odbc:excel
how to connect xlsx(2007 excel) - JDBC
how to connect xlsx(2007 excel)  i am not able connect to office 2007 excel file from jdbc
Advertisements
XLS JDBC Example
driver therefore you should use JDBC - ODBC bridge driver to connect your excel... .style1 { background-color: #FFFFCC; } XLS JDBC XlS JDBC driver is used to access xls file from java application. It is read only JDBC driver
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
How to insert rows from Excel spreadsheet into database by browsing the excel file?
How to insert rows from Excel spreadsheet into database by browsing the excel file?  I want to insert rows from excel sheet to database.for this i... the excel file using file browsing dialogue through form in JSP. How can i select
How to retrieve file name and path of an excel spreadsheet imported into Oracle Database
How to retrieve file name and path of an excel spreadsheet imported into Oracle Database  I imported an excel spreadsheet using sql developer into my... table for each spreadsheet but I want to obtain the path and filename of each
JDBC to EXcel
JDBC to EXcel  How to insert data in excel sheet from java
how to connect mysql with JDBC - JDBC
how to connect mysql with JDBC  I have created three tables in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
could not connect to the server - JDBC
could not connect to the server  Hii sir, I am working with a JBDC program now. Now i am trying to host it. when i am trying to connect...: Connection timed out: connect STACKTRACE: java.net.SocketException
Use JDBC to connect Microsoft Access
Use JDBC to connect Microsoft Access  How to use JDBC to connect Microsoft Access
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
how to connect jdbc
how to connect jdbc  package com.tcs.ilp.Try.Controller; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import
not able to connect to mysql using.. jdbc
not able to connect to mysql using.. jdbc   i am not able to connect to mysql using jdbc .. is there any classpath that i need to set..because i am using mysql-connector-java jar file..to connect to mysql.. Pls provide the steps
JDBC Connection code to connect servlet with oracle.
JDBC Connection code to connect servlet with oracle.  JDBC Connection code to connect servlet with oracle
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
Java and excel - JDBC
to a Jtable from where i can export to excel, i will like to format the column headers in excel using code. plz i nd help becos it is my project, as a serious student i tried using the following code but it gives me a distorted records in excel
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same... used JDBC ODBC to read from excel file. i am not able to append it using
what is ment by jdbc and how to connect with database?
what is ment by jdbc and how to connect with database?  i want answer for this question
Connect to MS Acces wothout using ODBC but JDBC - JDBC
Connect to MS Acces wothout using ODBC but JDBC  Hi, I want to connect my MS Access using JDBC but not ODBC. Please help me out. Thanks
can't connect to MySQL Server(10060) - JDBC
can't connect to MySQL Server(10060)  Hii Sir, I am working... MySQL front end. Can we connect to the MySQL server using the I.P address... write as the subject. Can we connect thorugh a MySQL Frontend. Kindly
exporting data to excel sheet - JDBC
exporting data to excel sheet  Sir i have already send request about... query in java swing program,i want to print the result about the query in excel... = wb.createSheet("Excel Sheet"); try{ Connection con = null
how to connect swings with jdbc... - Java Beginners
how to connect swings with jdbc...  Hi friends, Is it possible, to connect swings with data base like oracle....i want to store data into database..."); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test
Access Excel file through JDBC
Access Excel file through JDBC In this section, you will learn how to access excel file through Jdbc and display records in JTable. As you know Excel comes with an ODBC driver, so we are using JDBC-ODBC bridge driver to connect jdbc
java + excel data +graph - JDBC
java + excel data +graph  i am doin' a project in which i need to take up data from excel sheets and work upon them mathematically and finally draw a graph with the facility of drawing a trendline(in the graph)...also i need
export data from database to excel sheet - JDBC
export data from database to excel sheet  I am facing a problem about exporting required data from database table to ms-excel sheet.i mean whenever I execute a query then result will be display in MS-EXCEL sheet. please give me
JDBC Connection code to connect servlet with SQL Server 2008
JDBC Connection code to connect servlet with SQL Server 2008  Please ans me why it is not connect i use netbeans IDE7.0 Jdk 1.7 i also add... support for JDBC 4.0. i try Avery thing but i m not success so please ans me . My
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
Possibility of Creating a Spreadsheet in Java? - Java Beginners
Possibility of Creating a Spreadsheet in Java?  Is it possible to create a spreadsheet (like MS Excel) in java?   hi friend This code... = wb.createSheet("Excel sheet"); HSSFRow row = sheet.createRow((short)0); HSSFCell