0

I inherited a large codebase that uses SimpleJdbcInsertOperations.java for simple DB inserts. I know this class internally compiles an SQL statement behind the scenes from the map passed to the execute method. I need a way to get that SQL string from the object. Below is a sample code snippet...

private int insertIntoTable(){

    SimpleJdbcInsertOperations simpleJdbcInsertOperations = new SimpleJdbcInsert(
            MY_JDBC_TEMPLATE).withSchemaName(MY_SCHEMA).withTableName(MY_TABLE);

    //Map the columns for query
    Map<String, Object> myArguments = new HashMap<String, Object>();
    myArguments.put("COLUMN1", "1");
    myArguments.put("COLUMN2", "2");

    //TODO - NEED WAY TO GET COMPILED SQL STATEMENT


    return simpleJdbcInsertOperations.execute(myArguments);

}

Please no replies like "why not use jdbcTemplate instead?" The codebase is far too expensive to change at this point.

1 Answer 1

0

Wow This was easy to fix. Instead of using SimpleJdbcInsertOperations, I just changed the object reference to SimpleJdbcInsert. Then I can call SimpleJdbcInsert.getInsertString()

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.