0

I am looking for a way to insert a field/column into a record in MS-Access through Java. I believe that I need to use executeUpdate(INSERT...), however I cannot seem to get my program to add new fields/columns. Any help would be appreciated, and an example of the correct line would be even better.

Thanks, ~Crash

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Hughes
  • 339
  • 3
  • 15
  • 1
    Please provide your code sample, and welcome to SO. – I am Cavic Jan 07 '14 at 01:23
  • There is a difference between modifying the data in a table (`INSERT`, `UPDATE`, `DELETE`) and modifying the structure of the table itself (e.g. `ALTER TABLE`). A sample of your code would be useful as it's not clear what you want to accomplish and how you have tried to do it. – Matt Weller Jan 07 '14 at 02:17

1 Answers1

0

To add a new field (column) to an existing table you can use an ALTER TABLE statement like this:

String connectionString = 
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};" + 
        "DBQ=C:\\Users\\Public\\Database1.accdb;";
Connection con = DriverManager.getConnection(connectionString);
Statement st = con.createStatement();
st.execute("ALTER TABLE Customers ADD COLUMN Address TEXT(255)");

For more information on ALTER TABLE see

ALTER TABLE Statement (Microsoft Access SQL)

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418