1. #는 쿼리가 수행될 때, 다음과 같이 된다 


SELECT * FROM USER 

WHERE 

col = ?  


parameter : [값]


?에 bind된 값이 들어가게 된다. 



이 쿼리의 컴파일 된 내용을 재사용 할 수 있고, 파라미터에 따라 대입해주므로 효율적이다.

내부적으로 preparedStatement 객체에서 ? 에 들어갈 파라미터의 값을 set 해줌으로써 사용이 된다.

 

* preparedStatement는 한번 수행한 쿼리를 캐싱하는 객체



사용 용도 >>


#일 경우, 값에 사용한다.


myBatis : 컬럼명 = #{값}   

iBatis : 컬럼명 = #값#


* 쿼리에 작은 따옴표가 붙게 된다.



2. $는 쿼리가 수행될 때, 다음과 같이 된다(SQL injection 위험)


SELECT * FROM USER

WHERE 

col = 값



값이 넣어진 쿼리 자체로 수행이 된다.(상수)

즉, 문장 전체가 preparedStatement가 된다.


사용 용도 >>


$일 경우는 컬럼명이 동적으로 바뀌어야 할 때 사용한다. 또는 테이블명.


myBatis : ${컬럼명} = #{값}   

iBatis : $컬럼명$ = #{값}


* 쿼리에 작은따옴표가 붙지 않는다. 

값에 $를 사용하면 스트링의 경우 작은따옴표로 감싸지지 않기 때문에 에러 발생한다.



이렇게 사용하지 않으면 unknown column 이나 There is no readable property named  등등의 에러가 뜨게 된다



 출처 http://marobiana.tistory.com/60

블로그 이미지

왕왕왕왕

,


mybatis.zip





'JAVA > Spring 4.0' 카테고리의 다른 글

Spring4.0 스프링할때 web.xml과 jsp파일 인코딩  (0) 2015.10.07
Spring4.0 Mybatis $ , # 차이점  (0) 2015.10.01
Spring4.0 Mybatis (pom.xml)  (0) 2015.10.01
Spring4.0 JDBCTemplate  (0) 2015.10.01
Spring4.0 메이븐 프로젝트 구조  (0) 2015.09.22
블로그 이미지

왕왕왕왕

,


pom.xml에서 dependencies 탭을 눌러서 add버튼을 눌러서 추가한다.




추가하고 나서 저렇게 나오면 완료


'JAVA > Spring 4.0' 카테고리의 다른 글

Spring4.0 Mybatis $ , # 차이점  (0) 2015.10.01
Spring4.0 Mybatis 프로젝트 기본구조  (0) 2015.10.01
Spring4.0 JDBCTemplate  (0) 2015.10.01
Spring4.0 메이븐 프로젝트 구조  (0) 2015.09.22
Spring4.0 resources 경로이용하기  (0) 2015.09.16
블로그 이미지

왕왕왕왕

,

기본구조 구현된 스프링 프로젝트

JDBC.zip



Servlet-context.xml


<!-- template -->

<beans:bean name="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<beans:property name="driverClassName"                        value="oracle.jdbc.driver.OracleDriver" />

<beans:property name="url"

value="jdbc:oracle:thin:@localhost:1521:orcl" />

<beans:property name="username" value="scott" />

<beans:property name="password" value="tiger" />

</beans:bean>


<beans:bean name="template"

class="org.springframework.jdbc.core.JdbcTemplate">

<beans:property name="dataSource" ref="dataSource" />

</beans:bean>

<!-- END template -->



web.xml


 <resource-ref>

    <description>Connection</description>

    <res-ref-name>jdbc:/OracleDB</res-ref-name>

    <res-type>javax.sql.DataSource</res-type>

    <res-auth>Container</res-auth>

  </resource-ref>


pom.xml


<!-- JDBC Template -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>4.1.4.RELEASE</version>

</dependency>

<!-- END JDBC Template -->

블로그 이미지

왕왕왕왕

,
CREATE SEQUENCE  시퀀스명  
        START WITH n   
        INCREMENT BY n 
        MAXVALUE n |  NOMAXVALUE 
        MINVALUE n | NOMINVALUE


'데이터베이스 > Oracle' 카테고리의 다른 글

Oracle sys 계정로그인 & 비밀번호 변경  (0) 2015.10.06
Oracle 한글깨짐  (0) 2015.10.05
Oracle 코드에 들어가는 드라이버,URL  (0) 2015.08.25
Oracle 계정 Unlock  (0) 2015.08.24
Oracle 테이블 데이터 삭제  (0) 2015.08.20
블로그 이미지

왕왕왕왕

,

Jquery Submit 하기

JAVA/Jquery 2015. 9. 22. 17:40

            {

$('form').attr({

action : '../../../../ex/index.jsp',

method : 'post'

}).submit();

}

'JAVA > Jquery' 카테고리의 다른 글

Jquery Ajax 데이터 전송하기(한글깨짐방지)  (0) 2015.10.07
Jquery addClass  (0) 2015.10.02
Jquery select 제어  (0) 2015.08.25
Jquery 새창 화면중앙에 띄우기  (0) 2015.08.19
Jquery onload 사용법  (0) 2015.08.13
블로그 이미지

왕왕왕왕

,



'JAVA > Spring 4.0' 카테고리의 다른 글

Spring4.0 Mybatis (pom.xml)  (0) 2015.10.01
Spring4.0 JDBCTemplate  (0) 2015.10.01
Spring4.0 resources 경로이용하기  (0) 2015.09.16
Spring4.0 ModelAndView 이용한 전달  (0) 2015.09.16
Spring4.0 GET,POST 파라미터 전달  (0) 2015.09.16
블로그 이미지

왕왕왕왕

,


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>


<p>아이디 ${id}  </p>

<img alt="d" src="resources/image/king.jpg">

</body>

</html>


Servlet-context.xml에 resources 매핑이 되있어서

뷰페이지에서는 상대경로를 찾을 필요 없이 바로 resources부터 경로를 써주면된다.




블로그 이미지

왕왕왕왕

,