Home > Articles > Data

  • Print
  • + Share This
Like this article? We recommend

Updating the Database

Inserting data into a Derby database is as easy as writing some JDBC code, and Listing 2 illustrates two insertions.

Listing 2 Data insertion

s.execute("INSERT INTO " + ComponentTable +
   " VALUES(1, ’SYSTEM_UNIT_VENDOR1’, ’MONITOR_VENDOR1’, " +
   "’KEYBOARD_VENDOR3’, ’MOUSE’)");
s.execute("INSERT INTO " + PrincipalTable +
   " VALUES(’COMPUTER’, ’VENDOR1’, ’ENTRY_LEVEL’, 1)");

The code in Listing 2 inserts a row into each of our two database tables. Notice that I created the row in ComponentTable first; in PrincipalTable, I inserted the same value as the foreign key.

Let’s now pull some data from the database.

  • + Share This
  • 🔖 Save To Your Account