I added a KeyHolder interface and a GeneratedKeyHolder class (in
jdbc.support). They are used by the SqlUpdate.update(Object[],
KeyHolder) method.
Here is an example:
SqlUpdate su = new SqlUpdate(dataSource, "insert into Show2
(name) values(?)");
su.declareParameter(new SqlParameter("name", Types.VARCHAR));
su.setReturnGeneratedKeys(true);
su.setGeneratedKeysColumnNames(new String[] {"id"}); //this has
no effect for MySQL only DB2
su.compile();
Object[] val = {"Sven"};
KeyHolder kh = new GeneratedKeyHolder();
int updateCnt = su.update(val, kh);
int myKey = kh.getKey().intValue();
System.out.println("Key: " + myKey);
List myKeys = kh.getKeyList();
System.out.println(myKeys);
Direct JdbcTemplate use would look like:
KeyHolder kh = new GeneratedKeyHolder();
int rowsAffected =
getJdbcTemplate().update(newPreparedStatementCreator(args),
kh.getKeyList());
Thomas
jürgen höller [werk3AT] wrote:
>Thomas,
>
>We discussed changing the List argument for generated keys into a GeneratedKeysHolder class or the like, for easier access to a single generated key (the typical use case). If we change that, we should do so before 1.1 RC1, even if this means having 1.1 RC1 mid or late next week rather than on Monday.
>
>Juergen
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by BEA Weblogic Workshop
>FREE Java Enterprise J2EE developer tools!
>Get your free copy of BEA WebLogic Workshop 8.1 today.
>http://ads.osdn.com/?ad_idG21&alloc_id040&op=click
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>
|