Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert data into excel file using java code?

 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote below code to fetch data from excel work sheet. It is working file.


I want to transfer data from one sheet to another, so I wrote following code.

It is giving error at insert statement.
How to insert data into excel file using java code?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error? Post the full error message.

I don' think that ODBC can be used to alter Excel files - it can only read them. Either find a different Excel JDBC driver that can do this (although I doubt such a driver exists), or use a library like jExcelApi or Apache POI to alter the file programmatically.
 
Swastik Dey
Rancher
Posts: 1639
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing the single quotes in the query formation.

sql="insert into [Sheet2$] Values ("+columnValue+")";

should be

sql="insert into [Sheet2$] Values ('"+columnValue+"')";

and make sure the dsn has not been configured as readonly.
 
Raj Java Raj
Greenhorn
Posts: 5
IBM DB2 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Swastik Dey !
Great !! It working after removing Read Only DSN !!
Thanks.!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic