SpringBoot学习遇到的问题(持续更新)

1.问题:

### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 必须声明表变量 "@P0"。

; uncategorized SQLException; SQL state [S0001]; error code [1087]; 必须声明表变量 "@P0"。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 必须声明表变量 "@P0"。

解决:将形如:@Select("SELECT * FROM #{table}")中的 # 改为 $ .原因是SQL语句中表名作为一个变量,必须写成${tableName}, 而不是写成#{tableName}作为一个参数。

正确形式:@Select("SELECT * FROM %{table}")

2.CommandLineRunner实现命令行应用

https://www.cnblogs.com/harrychinese/p/SpringBoot_CommandLineRunner.html

3.mybatis批量插入的坑(其他sql语句一样会有)

sql server:参数名称过长

com.microsoft.sqlserver.jdbc.SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100

mysql:字符串内容过长

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (8346602 > 4194304). You can change this value on the server by setting the max_allowed_packet’ variable.

https://blog.csdn.net/vitaair/article/details/79753119

结论:

  • SqlServer 对语句的条数和参数的数量都有限制,分别是 1000 和 2100。
  • Mysql 对语句的长度有限制,默认是 4M。
  • Mybatis 对动态语句没有数量上的限制。

解决办法:SqlSession

4.多线程连接数据库导致连接失败。

HikariPool-1 - Connection is not available, request timed out after 30002ms

解决方法:减少多线程数量

5.使用SqlSession批量将数据插入数据库,关闭自动提交,false为关闭自动提交

SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);

 

posted @ 2019-04-09 15:00  carsonwuu  阅读(466)  评论(0编辑  收藏  举报