• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to INSERT records into Excel File using JDBC  RSS feed

 
Preeti Chopra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Neeraj Mishra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!