http://www.meiriyouke.net/?p=258
public int insertTable(LabelForm f) throws SQLException,ParseException
{
String content = f.getSiteId();
final String sql = "insert into TAG_INFO(SITE_ID,NAME,CONTENT) values(?,?,'"+content+"')";
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemplate().update(
new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection con) throws SQLException
{
PreparedStatement ps = getJdbcTemplate().getDataSource()
.getConnection().prepareStatement(sql,new String[]{ "SITE_ID" ,"NAME"});
ps.setString(1, "站点号");
ps.setString(2, "我的名字");
return ps;
}
}, keyHolder);
System.out.println("自动插入id============================" + keyHolder.getKey().intValue());
return keyHolder.getKey().intValue();
}