CannotGetJdbcConnectionException。jdbc连接mysql出现错误

在项目中遇到CannotGetJdbcConnectionException,尝试连接MySQL时失败。问题源于特定版本的JDBC驱动。解决方案是避免使用可能存在问题的新版本驱动,建议选择稳定版或回退到已知兼容的版本。
摘要由CSDN通过智能技术生成

项目场景:

CannotGetJdbcConnectionException。jdbc连接mysql出现错误


问题描述:

源代码如图。

package com.itheima.jdbctemplate;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;


public class JdbcTemplateDemo1 {
   

    public static void main(String[] args) {
   
        //准备数据源:spring的内置数据源
        try {
   
            DriverManagerDataSource ds = new DriverManagerDataSource();
            ds.setDriverClassName("com.mysql.jdbc.Driver");
            ds.setUrl( "jdbc:mysql://localhost:3306/pjpowernode");

            ds.setUsername("root");
            ds.setPassword("root");

            //1.创建JdbcTemplate对象
            JdbcTemplate jt = new JdbcTemplate();
            //给jt设置数据源
            jt.setDataSource(ds);
            //2.执行操作
            jt.execute("insert into account(name,money)values('ccc',1000)");
        } catch (Exception e) {
   
            e.printStackTrace();
        }
    }
}

导入的包版本。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值