Spring JDBC Template- To get back the inserted values using Keyholder
public List insert(final Action action){
final String insertIntoSql ="INSERT INTO MIPUSER_ACTIONS(IACTIONID, SACTIONNAME) VALUES (nextval('SEQ_MIPUSER_ACTIONS'),?)";
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection)
throws SQLException {
PreparedStatement ps = connection.prepareStatement(insertIntoSql.toString(), Statement.RETURN_GENERATED_KEYS);
ps.setString(1, action.getAction_name());
return ps;
}
}, holder);
KeyHolder newPersonId = holder;
System.out.println(newPersonId.getKeyList());
System.out.println(newPersonId.getKeys());
return newPersonId.getKeyList();
}
final String insertIntoSql ="INSERT INTO MIPUSER_ACTIONS(IACTIONID, SACTIONNAME) VALUES (nextval('SEQ_MIPUSER_ACTIONS'),?)";
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection)
throws SQLException {
PreparedStatement ps = connection.prepareStatement(insertIntoSql.toString(), Statement.RETURN_GENERATED_KEYS);
ps.setString(1, action.getAction_name());
return ps;
}
}, holder);
KeyHolder newPersonId = holder;
System.out.println(newPersonId.getKeyList());
System.out.println(newPersonId.getKeys());
return newPersonId.getKeyList();
}
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Triblend Melange
ReplyDelete