wood burning stoves 2.0*
The moose likes JDBC and the fly likes no error generated but no data is copied to Table1 after executing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "no error generated but no data is copied to Table1 after executing" Watch "no error generated but no data is copied to Table1 after executing" New topic
Author

no error generated but no data is copied to Table1 after executing

Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Hi Paras, and welcome to the Ranch!

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.
Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62
Hi Martin,
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..
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: no error generated but no data is copied to Table1 after executing
 
Similar Threads
multiple processes... only want one
java.sql.SQLException: Closed Connection
Cannot commit during managed transaction - Message-driven bean
Are there any problems using the same statement for multiple queries?
what is the scope of JSP objects ???