记录建立JDBC连接时的出错

在Spring框架中使用Druid数据库连接池时遇到连接问题,问题源于mysql版本与jdbc-connector版本不兼容。通过在pom.xml中指定jdbc-connector版本解决了这个问题,但仍有提示需要设置服务器身份验证,此部分暂未处理。
摘要由CSDN通过智能技术生成

记录建立JDBC连接时的出错

小组作业

在使用Spring框架创建 JDBC 连接时, 发生了几个问题, 我使用的IDE是 Intelij idea, 使用的数据库连接池是阿里巴巴提供的 Druid 数据库连接池, 也使用了 Maven 工具进行项目驱动的管理.

第一步:

类似于无框架的 JDBC 编程, 创建好 druid.properties 配置文件
在这里插入图片描述

第二步

创建了一个名为 applicationContext 的 xml 文件, 向里面添加了 bean 对象, 并配置了连接数据库需要的参数.
在这里插入图片描述
注意: 我的 applicationContext 文件是在resource 目录下的, 如果不在 resource 目录下需要对路径进行修改.

第三步:

test 目录下写了一个unit test 类, 测试一下连接是否正常.
在这里插入图片描述

第四步运行:

报错…

21:42:18.575 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3fc2959f: startup date [Sun Mar 29 21:42:18 BST 2020]; root of context hierarchy
21:42:18.870 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 2 bean definitions from class path resource [applicationContext.xml]
21:42:18.871 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@3fc2959f: org.springframework.beans.factory.support.DefaultListableBeanFactory@4c2bb6e0: defining beans [org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,dataSource]; root of factory hierarchy
21:42:18.913 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0'
21:42:19.015 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.driverClassName' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.url' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.username' in PropertySource 'localProperties' with value of type String
21:42:19.016 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'druid.password' in PropertySource 'localProperties' with value of type String
21:42:19.020 [main] DEBUG org.springframework.context.support
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值