?
Solved

Does Excel Have to be running to insert data into it from JAVA?

Posted on 2001-06-19
3
Medium Priority
?
142 Views
Last Modified: 2010-03-31
I can load an Excel spreadsheet, but it only works if I have the Spreadsheet open in Excel.  I would like this to load data at night from an Database table.   Any ideas or links anyone can point me to?
0
Comment
Question by:RedBane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
wgilster earned 200 total points
ID: 6207950
Use the ODBCJDBC driver. Here is an example

package classes;
import java.sql.*;

public class TestServer
{
  static
  {
      try  {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      }
      catch (Exception e) {
          System.err.println(e);
      }
  }

  public static void main(String args[]) {
      Connection conn=null;
      Statement stmt=null;
      String sql="";
      try {
          conn=DriverManager.getConnection("jdbc:odbc:excel","","");
          stmt=conn.createStatement();
          sql="INSERT INTO [Sheet1$] (FIELD_NAME1 FIELD_NAME2 FIELD_NAME3) VALUES (100,'String Value',200)";
          stmt.executeUpdate(sql);

      }
      catch (Exception e){
          System.err.println(e);
      }
      finally {
          try{
              stmt.close();
              conn.close();
              stmt=null;
              conn=null;
          }
          catch(Exception e){}
      }
  }
}
0
 
LVL 1

Expert Comment

by:wgilster
ID: 6210462
With my example above all you need to do is create is a DSN named "excel", and your ready to insert all the data you want.  If your importing data from a database just open the database the same way and import each resultset into Excel.
0
 

Author Comment

by:RedBane
ID: 6211595
Thanks for the help.

Its working now with the below statement.  I had to set up a data range in Excel.  I can not get it to work by putting in the column names in the first part of the Insert statement.

sqlProd = "INSERT INTO \"ProductWS$\" VALUES ("+ProdID+",\'Desc\',\'TransType\')";

Thanks
Rob
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question