我在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 clientXMLfile是
<?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);
}
}发布于 2018-12-14 19:46:47
要解决此问题,首选的解决方案是将所有客户端程序升级为使用4.1.1或更高版本的客户端库。如果无法做到这一点,请使用以下方法之一:
1)要使用4.1版本之前的客户端程序连接到服务器,请使用仍具有4.1版本之前样式密码的帐户。
2)对于每个需要使用4.1版本之前的客户端程序的用户,将密码重置为4.1版本之前的样式。这可以使用SET PASSWORD语句和OLD_PASSWORD()函数完成:
mysql> SET PASSWORD FOR
-> 'user'@'host' = OLD_PASSWORD('new_password');https://stackoverflow.com/questions/53779084
复制相似问题