[mysql] 간단한 팁 몇 가지
단일 jdbc 연결로 여러개의 쿼리를 실행하고 싶은 경우
- JDBC connection string에 allowMultiQuery=true 추가 - Stored Procedure 활용
http://stackoverflow.com/questions/10797794/multiple-queries-executed-in-java-in-single-statement
insert/update를 한 방에 처리하고 싶은 경우
- insert ... on duplicate key update 구문으로 처리 - 내 경우는 unique key를 걸고 처리하였음 - "mysql"에만 해당하는 문법임.
ex. insert into product (a, b, c) values (1, 2, 3) on duplicate key update c = c + 1
http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html
auto_increment 의 최종 값을 알고 싶을 때
- last_insert_id() 이용 - 변수에 담고 싶으면 아래와 같이 실행
... select last_insert_id into @last_id select @last_id













