• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to INSERT records into Excel File using JDBC

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Does anyone know how to update records in an Excel file using JDBC. This is what I did
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:Excel","","");
Statement st = con.createStatement();
String sql = "INSERT INTO sheet1$ VALUES ('Preeti', 'Chopra' )";
st.executeUpdate(sql);
st.close();
con.close();
but the system throws the following exception
Message SQLException = [Microsoft][ODBC Excel Driver] Syntax error in INSERT INTO statement.
However, the code works perfectly when used with MSAccess.
Can anybody give any idea please???
Regards
Preeti
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u want to write to excel using data from database the use
IO of java
The code u have shown simply dont say that what type of seperator u are going to use, But still I am a linux worker
So if u dont get the result by using it
first try to write to flat file then to excel using proper seperator
If not i will mail u the codes om monday
With regards
Neeraj
 
Preeti Chopra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Neeraj,
Thanx for your reply. Let us assume that i use separators also, I guess that will not automate the writing to excel file. It will be a plain text file. Also I need to find out how to write to different sheets of Excel file, how does one achieve that?
Any idea?
Regards
Preeti
reply
    Bookmark Topic Watch Topic
  • New Topic