Mybatis + PostgreSQL database error
Exception ......nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: ID,PW와 에러 내용 한글 깨져서 나옴.
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: ID,PW와 에러 내용 한글 깨져서 나옴.
exception=org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: ID,PW와 에러 내용 한글 깨져서 나옴.
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: ID,PW와 에러 내용 한글 깨져서 나옴.
보통 대부분의 에러는 log에 전부 나와있다.
JDBC/Mybatis 연동중에 발생한 에러임.
db연동 에러의 궁극적인 원인은 내가 DAO, DTO, VO 의 개념을 잘 모르고 있었다.
이론적인 부분부터 공부하며 수정함.
1. Mapper.xml - namespace, resultType Change
<mapper namespace="com.sample.domain.FileUploadMapper" >
<select id="getFileName" resultMap="file" resultType="com.sample.domain.FileUploadMapper">
SELECT * FROM FILENAME;
</select>
delete
<mapper namespace="mapper" >
<select id="getFileName" resultType="com.sample.domain.FileUploadDTO">
SELECT * FROM PUBLIC.FILENAME;
</select>
</mapper>
update
2. mybatis-config - sqlmap.xml Mapping delete > settings code create.
<configuration>
<mappers>
<mapper resource="com/sample/resources/config/SqlMap.xml" />
</mappers>
</configuration>
delete
<!-- 1. properties 파일 연결
<properties resource="경로/jdbc.properties"></properties> -->
<settings>
<!-- Camel Case, Snake Case 변경 코드 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<!-- 2. vo 연결 및 alias(별칭) 지정 -->
<typeAliases>
<typeAlias type="com.sample.domain.SampleVO" alias="vo"/>
</typeAliases>
<!-- 3. DB 서버 정보 -->
<environments default="sampledb">
<environment id="sampledb">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/sampledb"/>
<property name="username" value="sampledb"/>
<property name="password" value="1234"/>
</dataSource>
</environment>
</environments>
update
3. root-context.xml update
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource" >
<property name="driverClass" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/DBNAME" />
<property name="username" value="ID" />
<property name="password" value="PW" />
</bean>
delete
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:/jdbc.properties" />
<property name="fileEncoding" value="UTF-8" />
</bean>
<!-- JDBC-PostgreSQL -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- mybatis setting - sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:/mapper/*.xml" />
<property name="configLocation" value="classpath:/config/mybatis-config.xml" />
<!-- 트랜잭션 관리를 위한 것 -->
<property name="transactionFactory">
<bean class="org.mybatis.spring.transaction.SpringManagedTransactionFactory" />
</property>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
</bean>
update
결국 이 에러의 원인도 경로 설정이었다.
오타, 경로만 조심하면 에러가 많이 줄 것 같다.
주의해야겠다.