JDBC - (Insert|Update) DML Statament

> Procedural Languages > Java > JDBC (Java Database Connectivity)

1 - About

DML statement in JDBC


3 - Retrieving key

The Statement method executeUpdate is called with two parameters, the first is the SQL statement to be executed, the second is an array of String containing the column name that should be returned when getGeneratedKeys is called.

Retrieving a named column using executeUpdate and getGeneratedKeys

String keyColumn[] = {"ORDER_ID"};
Statement stmt = conn.createStatement();
int rows = stmt.executeUpdate("INSERT INTO ORDERS " +
"VALUES (966431502, ’BILLG’)",
ResultSet rs = stmt.getGeneratedKeys();