푸린세스

p190 MySQL~Oracle 본문

spring/구멍가게코딩단-스프링

p190 MySQL~Oracle

푸곰주 2023. 5. 3. 10:25

selectKey 부분은 MySQL로는 어떻게 하나요??

MySQL이 시퀀스가 없어서 어떻게 해야되는지 잘 모르겠습니다

 

 

A:

selectkey 의 before가 아니라 after를 이용하고 select last_insert_id( ) 를 이용하면 됩니다.

<insert id="insert">
insert into tbl_board (title,content,writer)
values(#{title},#{content},#{writer})

<selectKey order="AFTER" resultType="long" keyProperty="bno">
select last_insert_id()
</selectKey>
</insert>

 

 


<insert id = "insertSelectKey">
<selectKey keyProperty="bno" order = "BEFORE" resultType = "long">
select max(bno)+1 from tbl_board;
</selectKey>

insert into tbl_board (bno, title, content, writer)
values (#{bno}, #{title}, #{content}, #{writer})
</insert>
저는 이렇게 해봤는데
적어주신 방법이랑 어떤 차이가 있을까요??

 

 

 

 

 

 

 

 

 

출처- 구멍가게코딩단 네이버카페

'spring > 구멍가게코딩단-스프링' 카테고리의 다른 글

rownum과 index  (0) 2023.05.06
MySQL ~ log4jdbc 설정하기.  (0) 2023.05.03
스프링MVC의 기본사상  (0) 2023.05.02
스프링MVC 기본구조  (0) 2023.05.02
MyBatis ~ 스프링과 연동처리  (0) 2023.05.01