码迷,mamicode.com
首页 > 数据库 > 详细

SpringBoot整合JdbcTemplate连接Mysql

时间:2019-02-16 15:34:11      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:except   sql   cep   contex   boot   pac   art   pre   cut   

 

import java.io.IOException;

import javax.sql.DataSource;

import org.apache.ignite.IgniteSystemProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;


@SpringBootApplication
public class Application {

    public static void main(String[] args) throws IOException {
        

        SpringApplication.run(Application.class, args);
    }

    @Bean
    public JdbcTemplate jdbcTemplate() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");

        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        return jdbcTemplate;
    }

}

添加依赖:

apply plugin: ‘org.springframework.boot‘
apply plugin: ‘io.spring.dependency-management‘

springBoot {
executable = true
mainClass = ‘com.test.Application‘
}

dependencies {
compile "org.springframework.boot:spring-boot-starter-web:${verSpringBoot}"

compile "mysql:mysql-connector-java:5.1.21"

}

SpringBoot整合JdbcTemplate连接Mysql

标签:except   sql   cep   contex   boot   pac   art   pre   cut   

原文地址:https://www.cnblogs.com/liangblog/p/10387769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!