ibatis를 이용해서 dao를 만들고 있는데 ibatis의 insert나 select update할때 한번에 한개의 query 밖에 쓰지 못해서 stored procedure로 만들어야 고민고민중이었는데 검색해보니 jdbc 드라이버에서 옵션설정을 하면 한번에 여러개의 쿼리를 보낼 수 있다는군요 ; 를 구분자로 씁니다.
mysql은 보안문제로 allowMultiQueries 디폴트 false값을 갖게 했다고 합니다.
(sql injection attack 방지)
ibatis처럼 바인딩해서 주로 쓰는 경우는 문제가 좀 덜하지 않을까 싶습니다.
( $sql$ 이런거 쓰실때는 주의 )
mysql jdbc 드라이버 속성 설정
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
allowMultiQueries Allow the use of ';' to delimit multiple queries during one statement (true/false), defaults to 'false' false 3.1.1
찾은 원문 내용들입니다.
Multiple Statements with MySQL and JDBC
url : http://www.petefreitag.com/item/357.cfm
Cameron Childress pointed out the allowMultiQueries setting in the MySQL JDBC driver on the CFGURU list.
It is set to false by default to protect you from SQL Injection attacks.
When set to true MySQL will allow multiple SQL statements (seperated by a semi-colon) to be executed in a single CFQUERY tag.
If you need to run multiple statements in a single CFQUERY,
Dave Watts suggested creating another datasource with this setting turned on, which is only to be used when your running multiple statements.
But don't let this stop you from using prepared statements with CFQUERYPARAM,
just because MySQL is safe by default - it is still a best practice, adds performance and type safety.
|