学习jdbcTemplate连接jdbc遇到的一些问题汇总

学习jdbcTemplate连接jdbc遇到的一些问题汇总

问题一:Cannot load driver class: com.mysql.jdbc.Driver

首先在连接数据库时,日志中报错 Cannot load driver class: com.mysql.jdbc.Driver
称无法连接driver,后来我查阅资料发现:需要下载mysql-connector-java-5.1.47-bin.jar中,并且将jai包放置在web-if的lib文件下。

问题二 数据库5.5.45之后的改变

According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
大概意思是mySQl在5.5.45+, 5.6.26+ and 5.7.6
这几个版本中尝试本地连接数据库有一些约束和要求,可以在URI的内容之后加上
?useUnicode=true&characterEncoding=utf-8&useSSL=false‘ 就没有问题了。

问题三密码写错

Could not get JDBC Connection Cannot create PoolableConnectionFactory (Access denied for user ‘root’@‘localhost’ (using password: YES)) 这个问题应该是你的进入SQL数据库的密码写错了,把密码写对即可。

#问题四

jdbcTemplate.update("insert into t_user(username,PASSWORD) values(?,?)","tom"
				,"998");

写入value这里两个问号不需要写成‘?’ ‘?’ 这样的形式

你可能感兴趣的:(java)