【发布时间】:2023-03-09 19:39:01
【问题描述】:
我正在eclipse中制作一个简单的员工测试文件。但它显示了无法获取 JDBC 连接的错误。请帮帮我。
错误是
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
XML文件是
<?xml version="1.0" encoding="UTF-8"?>
<bean
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
name="dataSource" p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/mydb" p:username="root"
p:password="banjit" />
<bean class="org.springframework.jdbc.core.JdbcTemplate"
name="jdbcTemplate" p:dataSource-ref="dataSource" />
Java 代码是
public class Test {
public static void main(String[] args) {
ApplicationContext context =new ClassPathXmlApplicationContext("com/banjit/spring/springjdbc/refconfig.xml");
JdbcTemplate jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
String sql = "insert into employee values (?,?,?)";
int result = jdbcTemplate.update(sql, new Integer(1), "Banjit","Das");
System.out.println("Numbers of records inserted "+result);
}
}
【问题讨论】:
-
您的数据库主机是否允许 jdbc?
-
你有
consider[ed] upgrading MySQL client吗? -
是的@MWB 它允许
-
您使用的是哪个版本的 MySQL 以及哪个版本的 MySQL Connector/J?请发布完整的异常堆栈跟踪,而不仅仅是消息。
标签: java mysql spring spring-boot jdbc