0


I'm reading a lot of data and want to inset them in a database. So far, not a big deal and everything was working fine using a prepared statement and firing it for every row.
Now I switched to batch processing for better performance and get an error:
java.sql.SQLException: Fehler bei Stapelverarbeitung aufgetreten: batch must be either executed or cleared
The only information I found on SO about this specific error is this question dealing with different types of sql stements for one batch.
However, that's not what I'm doing, here's the code:

    @Override
    public void addRow(String[] row) throws SQLException, ClassNotFoundException, IOException {
        PreparedStatement s = q.getStatement();
        for (int i = 0; i < row.length; i++) {
            s.setString(i + 1, row[i]);
        }
        s.addBatch();

    }

    @Override
    public void done() {
        try {
            DatabaseUtils.execute(q); //Error is thrown here!
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


Additional information: q is simple wrapper for PreparedStatements which allwos me to load it easier, after the first getStatement() call no further changes to the statement are possible. The statment is a simple INSERT like INSERT INTO TABLE1 VALUES (?, ?, ?, ?)
DatabaseUtils.execute does nothing else as query.getStatement().execute();.
Database is an Oracle Database V10.205, JDK 1.6´, Driver is ojdbc6
Can someone please explain me why the error is thrown?

1 Answer 1

2

I believe

DatabaseUtils.execute does nothing else as query.getStatement().execute();

is the problem here. Try changing it to query.getStatement().executeBatch() or create a new method DatabaseUtils.executeBatch that will do that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.