java - JdbcDaoSupport with a SQL SELECT FROM INSERT -


i trying create "select insert" within spring jdbcdaosupport class , having trouble figuring out how get data select statement , return it.

my eventjdbctemplate (my daoimpl):

@service public class eventjdbctemplate extends jdbcdaosupport implements eventdao {  private static final logger logger = logger.getlogger(eventjdbctemplate.class);  private static final string sql_insert_event = "select event_id final table " +         "(insert ebt10dbb.sb0401t0 (event_name, host_name, user_id) " +         "values(?, ?, \'emp0321\'))";  @autowired public eventjdbctemplate(datasource pdatasource) {     super.setdatasource(pdatasource); }   @override public integer createevent(eventbean peventbean) { //(integer id, string eventname)     if (logger.istraceenabled()) {         logger.trace("entering create(event event) of eventjdbctemplate.");     }     // sql works, insert only.      /*this.getjdbctemplate().query(sql_insert_event, new object[]{         peventbean.geteventname(),         peventbean.gethostname()     });*/      final list eventlist = this.getjdbctemplate().query(sql_insert_event, new object[]{         peventbean.geteventname(),         peventbean.gethostname()         }, new eventrowmapper()     );      event event = null;     (int = 0; < eventlist.size(); i++) {         event = (event)eventlist.get(i);     }      if (logger.istraceenabled()) {         logger.trace("exiting create(event event) of eventjdbctemplate.");     }     //return statement -- should return either entire "peventbean", or     //just unique key, "event_id".             return event.getid(); } 

eventrowmapper class (not sure i'll need select or not):

public class eventrowmapper implements rowmapper<event> {      @override     public event maprow(resultset rs, int rownum) throws sqlexception {         final eventbuilder event = new eventimpl.eventbuilder();         event.setid(rs.getint("event_id"));         event.seteventname("event_name");         event.sethostname("host_name");         return event.build();     }  } 

so goal return integer value unique key (event_id) created insert sql.

you can use simplejdbcinsert provided spring generated keys, see following documentation provided spring section

13.5.2 retrieving auto-generated keys using simplejdbcinsert

here link


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -