2012년 7월 27일 금요일

sqlite에 auto increment 값 입력하고 입력된 일련번호 값 받아오기


CREATE TABLE userInfo
  userId INTEGER PRIMARY KEY,
  first_name TEXT NOT NULL,
  last_name TEXT NOT NULL,
);


<insert id="insertUser" parameterType="userVo">
<![CDATA[
INSERT INTO userInfo (
first_name
   ,last_name
) VALUES (
    #{firstName}
   ,#{lastName}
)
]]>
<selectKey keyProperty="userId" resultType="int">
SELECT LAST_INSERT_ROWID()
</selectKey>
</insert>


public class UserInfoDAOImpl extends BaseDAO implements UserInfoDAO{
    @Override
    public int insertJob(UserVo userVo) throws OSPException {
        int returnVal = -1;
        returnVal = (Integer) getSqlSession().insert("com.test.dao.UserInfoDAO.insertUser", userVo);
       
        System.out.println("userId="+userVo.getUserId());
       
        return returnVal;
    }
   
}