Solved

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

Posted on 2001-06-19
3
139 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 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

697 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