Example usage for java.sql Statement NO_GENERATED_KEYS

List of usage examples for java.sql Statement NO_GENERATED_KEYS

Introduction

In this page you can find the example usage for java.sql Statement NO_GENERATED_KEYS.

Prototype

int NO_GENERATED_KEYS

To view the source code for java.sql Statement NO_GENERATED_KEYS.

Click Source Link

Document

The constant indicating that generated keys should not be made available for retrieval.

Usage

From source file:org.restlet.ext.jdbc.JdbcClientHelper.java

/**
 * Helper/*from ww  w .  jav a2  s  .co m*/
 * 
 * @param connection
 * @param returnGeneratedKeys
 * @param sqlRequests
 * @return the result of the last executed SQL request
 */
private JdbcResult handleSqlRequests(Connection connection, boolean returnGeneratedKeys,
        List<String> sqlRequests) {
    JdbcResult result = null;
    try {
        connection.setAutoCommit(true);
        Statement statement = connection.createStatement();
        for (String sqlRequest : sqlRequests) {
            statement.execute(sqlRequest,
                    returnGeneratedKeys ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
            result = new JdbcResult(statement);
        }

        // Commit any changes to the database
        if (!connection.getAutoCommit()) {
            connection.commit();
        }
    } catch (SQLException se) {
        getLogger().log(Level.WARNING, "Error while processing the SQL requests", se);
        try {
            if (!connection.getAutoCommit()) {
                connection.rollback();
            }
        } catch (SQLException se2) {
            getLogger().log(Level.WARNING, "Error while rollbacking the transaction", se);
        }
    }
    return result;

}