spirngBoot鏈接msql

注意事項:配置mysql-connector-java的版本,java

//不一樣版本的mysql的驅動不同mysql

//比較低的版本 spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring

//高版本 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver <dependency> <groupId>org.springframework.boot</groupId>sql

<artifactId>spring-boot-starter-jdbc</artifactId>
		
    </dependency>

    <dependency>
	
        <groupId>mysql</groupId>
		
        <artifactId>mysql-connector-java</artifactId>
		
        <version>5.1.37</version>
		
        <scope>runtime</scope>
		
    </dependency>
	
	//配置文檔

spring.datasource.username=rootspring-boot

spring.datasource.password=123456url

spring.datasource.driver-class-name=com.mysql.jdbc.Driver.net

spring.datasource.url=jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=truecode

public class Test3ApplicationTests {

@Autowired DataSource dataSource;blog

[@Test](https://my.oschina.net/azibug)

public void contextLoads() throws SQLException {

    System.out.println(dataSource.getClass());
	
    Connection connection = dataSource.getConnection();
	
    System.out.println(connection);
	
    connection.close();
	
}

}文檔

相關文章
相關標籤/搜索