자주 잊어버리니 기록!


Download

$ wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.21.tar.gz


설정

maven

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.21</version>
</dependency>

gradle

// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'


JDBC Driver class

com.mysql.cj.jdbc.Driver


MySQL 5.1 이하

 Click here to expand...
com.mysql.jdbc.Driver


JDBC URL format

jdbc:mysql://[host][,failoverhost...][:port]/[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...


property file

jdbc:mysql://localhost:3306/lesstif?useUnicode=true&characterEncoding=utf8


XML

& 가 특수 문자이므로 &amp; 로 변경

jdbc:mysql://localhost:3306/lesstif?useUnicode=true&amp;characterEncoding=utf8
  • useUnicode 의 기본 설정은 true 이므로 빼도 된다.
  • characterEncoding 의 기본 설정은 'autodetect' 다.

Spring DataSource 용

<bean id="myDS"
		class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/lesstif?useUnicode=true&amp;characterEncoding=utf8" />
		<property name="username" value="userid" />
		<property name="password" value="useriduserPwd" />
	</bean> 


Ref





blog comments powered by Disqus