자바스프링 DB연결

채종윤·2023년 8월 28일
0
  1. pom.xml에

test위에

com.oracle.database.jdbc
ojdbc8
23.2.0.0

    maven repository
    
    
  1. severs 폴더 - context.xml
    <Resource name="jdbc/ora"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@localhost:1521:xe"
    username="spring" //db이름
    password="spring" //db 패스워드
    maxActive="5"
    maxIdle="3"/>

3.pom.xml

org.springframework
spring-jdbc
${org.springframework-version}

추가

  1. root-context.xml
    (/beans위에)




    root-context.xml에서 value 를 contenxt.xml에서 resource name과 같게 해야한다 jdbc/ora

  2. mybatis
    1)
    maven repostive - mybatis

    org.mybatis mybatis 3.5.13

test위에

mybatis spring 3.02

org.mybatis
mybatis-spring
3.0.2

둘다 pom.xmi test위에

2)

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:/mybatis/mybatis-config.xml" />
		<property name="mapperLocations" value="classpath:/mybatis/mybatis-mapper.xml" />
	</bean>
	<bean id="sqlSessoinTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
	</bean>

root-context.xml
src/main/resources -> mybatis 폴더생성->mybatis-mapper.xml파일생성

select * from Member where mid = #{id} select * from Member ORDER BY mid insert into member(mid, mname, mpwd, mintro) values(#{mid}, #{mname}, #{mpwd}, #{mintro}) update member set mid=#{mid}, mname=#{mname}, mpwd=#{mpwd}, mintro=#{mintro} where mid=#{mid} delete from member where mid=#{mid} ![](https://velog.velcdn.com/images/cjy205/post/43eeeb54-39eb-476e-b18c-98f87d54407b/image.png) xml안에 작성

Spring Legacy project -> mvc -> pom.xml -> version 1.6->1.8 3.1.1->5.3.29-> framework 복사해서 spring-jdbc로 수정 -> ojdbc8,mybatis,mybatisspring

com.oracle.database.jdbc
ojdbc8
23.2.0.0

	<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
org.mybatis mybatis 3.5.13 org.mybatis mybatis-spring 1.3.3 위에 붙여넣기

root-context.xml -> JndiObjectFactoryBean정의(Data source),SqlSessionFactoryBean정의(SqlSession)

profile
안녕하세요. 백앤드 개발자를 목표로 하고 있습니다!

0개의 댓글