使用springjdbctemplate模板链接mysql数据库8.0遇到的坑

jar包不同连接方式不同

mysql-connector-java-8.0.11.jar

com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar

dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql:///Spring?serverTimezone=UTC ");

 

手动创建数据库数据表

create database Spring;
USE Spring
create table account(
	id int primary key auto_increment,
	name varChar(10),
	mooney double
);
package jdbc;

import com.mchange.v2.c3p0.DriverManagerDataSource;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;



public class DriverTest {

    @Test
    public void  test1(){
        DriverManagerDataSource dataSource =  new DriverManagerDataSource();
        dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql:///Spring?serverTimezone=UTC ");
        dataSource.setUser("root");
        dataSource.setPassword("123456");
        JdbcTemplate jdbcTemplate =  new  JdbcTemplate(dataSource);

        jdbcTemplate.update("insert into account values(null,?,?)" ,"张龙",10000);
    }
}

 

你可能感兴趣的:(框架相关)