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.
Thanks for using the code tags. However, you've put your code outside of the tags, so it didn't work. I've repaired that.
You didn't explain your problem in much detail, so I'm only guessing. I think the problem is that you're using the UPDATE statement, which modifies existing data. To copy data from table to table, you should use the INSERT statement. You might want to read some SQL tutorial to understand these things better.
Joined: May 22, 2012
Thanks.. for your help. Now at least i know where my code went wrong. But still i am unable to write a code to perform what i want i.e. I have an excel sheet with fewer columns and a table in ms access with greater no. of columns. I want to match the column names of excel sheet with table and if it matches i want the data of the column to be copied in table.
NOTE: Now here's the catch- If the excel sheet has four records, i want those 4 records in the table(only those columns of records that are also in the table).
Pease if you could provide me with a demo code or even the basic idea how to do it, i would be grateful.
I need this code desperately to run..
Generally, the properties of tables and other database objects are accessible via the Connection.getMetaData() method. This methods returns the DatabaseMetaData instance, which should contain this kind of information. You might be able to get the column names of the tables from it. Have a look at the DatabaseMetaData in Javadoc. However, I don't have any experience with JDBC-ODBC bridge you need to use to access Excel sheets, there might be some caveats in using it.
As I understand it, you're reading the data from an Excel sheet and writing them to MS Access database. There might be other options available: for example, you could read the data from Excel using a library which accesses the Excel files in their spreadsheet format (eg. Apache POI). That would probably be more work to do, but if you could make this work, you would certainly be able to read column headers this way.
You might also consider programming the whole thing as a VBA macro in Excel (or maybe in Access). It might be easier that way than using Java to do it, depending on your experience with VB/VBA.