1

I set "AutoCommit" flag for java.sql.Connection object as false when executing SPARQL Query but the flag is ignored. Given below is the part of the code that executes the Query.

    Connection conn;
    OracleDataSource oracleDataSource;
    try {
        oracleDataSource = new OracleDataSource();
        oracleDataSource.setURL("");
        oracleDataSource.setUser("");
        oracleDataSource.setPassword("");
        conn = oracleDataSource.getConnection();
        conn.setAutoCommit(false);
    } catch (SQLException e) {
        LOGGER.error("Exception occurred in preparing connection: ", e.getMessage());
        throw (e);
    }

    String sparqlInsertQuery = "BEGIN SEM_APIS.UPDATE_MODEL('RDF_MODEL','xxxxxxxx'); END;";

    try (Statement stmt = conn.createStatement()) {
        stmt.executeUpdate(sparqlInsertQuery);
    } catch (SQLException e) {
        LOGGER.error("Cannot Execute Query: ", e);
        throw (e);
    }

    //conn.commit();
    conn.close();

Eventhough I have added "conn.setAutoCommit(false);", the statement "stmt.executeUpdate(sparqlInsertQuery);" commits the Triples into the Model. Instead of SPARQL Query, if I use SQL Query, the "AutoCommit" flag value is considered and everything works fine.

Mohan D
  • 11
  • 3
  • i'm pretty sure the connection.close() forces a commit. – OldProgrammer Feb 14 '20 at 15:56
  • @OldProgrammer Only with Oracle (and maybe only older Oracle drivers), afaik, most JDBC drivers will rollback on close without an explicit commit when auto-commit is disabled. – Mark Rotteveel Feb 14 '20 at 18:58
  • Related: [Disable oracle autocommit on close connection](https://stackoverflow.com/questions/23263139/disable-oracle-autocommit-on-close-connection), [Does Java Connection.close rollback?](https://stackoverflow.com/questions/218350/does-java-connection-close-rollback) – Mark Rotteveel Feb 14 '20 at 19:00
  • Hello everyone. This post is not about connection.close(). Its about AutoCommit flag works for SQL Query but not for SPARQL Query. Even if I remove the statement conn.close(); I could see the Triples committed to the RDF Model. – Mohan D Feb 15 '20 at 16:09
  • @MarkRotteveel I believe this post is not duplicate of the post you have tagged. As I mentioned, stmt.executeUpdate(sparqlInsertQuery); commits Triples to RDF Model which should not happen when conn.setAutoCommit(false); is set. – Mohan D Feb 15 '20 at 16:12

0 Answers0