Spring笔记02 Idea运行示例项目的坑
表建好之后,Idea里面直接打开示例工程跑不起来,mysql的依赖有问题
1 | Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver |
对比发现Maven路径不对
这是自己创建的可以运行的Maven项目配置
这是导入工程的配置
修改路径
1 | /usr/local/Cellar/maven/3.6.2/libexec |
解决Driver问题
下一个bug
Idea中点运行
1 | MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server |
在MySQL Workbench中输入
1 | USE mysql; |
Idea中提示变成了
1 | Exception in thread "main" java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property. |
在连接数据库的url后加上编码方式
1 | Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/groot?useUnicode=true&characterEncoding=utf8","root","iamgroot"); |
成功
总结:
- 修改Preference->Build, Execution, Deployment->Build Tools->Maven中路径
- 在连接数据库的url后加上编码方式