This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I haven't used JDBC to access Excel files, but the only thing that I can see that would certainly cause a problem is if the result String contained a single-quote itself, breaking your quoting. For example, "This doesn't work" would cause confusion since the ' in doesn't would terminate the quoting for result.
Otherwise, my only recommendation is to verify that your syntax is correct. What does [test1$] represent: a worksheet, cell, range, name? If it's a cell, can you insert three values into a single cell? Again, I know Excel pretty well (though it's been a while since I've done serious macros) and JDBC, but I've never put them together.
It's probably a bit late, but there are also a couple Open Source APIs for reading and writing Excel workbooks directly. One is an Apache project (POI I think), and another was just mentioned today, Java Excel API.
Joined: Jan 27, 2005
Hi David, Thanks a lot for the quick reply!!! The [tablename$] is the special syntax for representing an Excel work sheet ( a table otherwise in JDBC), I was trying to be very careful when dealing with the double or single quotes stuff. It seems that the problem is something about that I have to use update JDBC statement instead of mere query statement. However, that is my biggest confusion, becuase I already used the PreparedStatement.executeUpdate() method. Anyway, if it still does not work out, I will check out the Java Excel API link you gave me! Thanks again for your help!
I have solved recently same problem of excel file and jdbc but as you asked to insert data in excel file, then i some confused becouse i have create fresh excel file using java code and for this i used apache's POI package, if you are using the same then this package will help you to insert data into existing file as well as create fresh excelfile. You will get more detail of this package here...
Hi guys, Thanks a lot for all of your replies! I finally just gave up rolling around with JDBC to deal with MS Excel. I shifted to apache POI HSSF packages, it turned out to be satisfactory. However, when I was trying to write Japanese Characters to the *.xls file, the result was all chaotic characters. In addition, it's not that the .xls file does not support Japanese, I can well paste and write Japanese characters into it. It seems the HSSF package is not so well writing characters other than standard ASCIIs. So what I fianlly did was to use the HSSF to write to .cvs files, which are *.xls format compatible.