Insert data

Lenses JDBC also can perform SQL inserts, which result in new records being written to a Kafka topic. The topic written to is the subject of the INSERT INTO clause, as is in a regular SQL query.

To perform an insert, we obtain a statement, as we have done previously. Then we use the executeUpdate() method, passing in a well-formed SQL insert query. For example if my insert statement is:

INSERT INTO mytopic (
    name
    , city
    , lat
    , long
) VALUES (
    'James T Kirk'
    , 'Iowa City'
    , 43.3
    , -54.2
)

The we would set:

Statement stmt = conn.createStatement();
int result = stmt.executeUpdate(updateStmtstring);

The result returned indicates success.