最近在做Mysql的批量入库时,执行到PreparedStatment.executeBatch()这一句时,报错:prepared statement contains too many placeholders,提示占位符过多~,可是我发现我入库的表也才40+个字段,应该不至于吧,但是……
在批量入库时,Mysql会将insert语句拼装成如下格式:
insert into tablename(字段1, 字段2, 字段3, ……, 字段45) values(:字段1, :字段2, :字段3, ……, :字段45), (:字段1, :字段2, :字段3, ……, :字段45), (:字段1, :字段2, :字段3, ……, :字段45), ……, (:字段1, :字段2, :字段3, ……, :字段45)
比如我批量入库的对象是3000+条记录,虽然我把它封装成一个List集合,但是集合里面每个元素都有45个key(一个key对应一个字段)。sql被拼装成上述格式后,占位符的个数达到3000*45=135000,大于mysql对占位符的最高限制65535。
所以需要注意的是,批量入库时,占位符的个数不再是45,而是45与条数的乘积。
教训:尝试把List分批,每批再分别批量,确保每批所产生的占位符个数小于mysql的最高限制65535.
一般情况下,这种错误在批量入库的时候容易出现,而往往在大批量数据的情况下出现,多多注意。
相关推荐
ERROR 1615 (HY000): Prepared statement needs to be re-prepared 经过测试,发现不是合服脚本的问题。经过一番搜索。发现原来是mysql的变量值设置不合理引起的,调整以下值: table_open_cache 64=>16384 table_...
jdbc中statement和prepared区别,jdbc中statement和prepared区别
何登成大牛写的, 给大家共享一下下, 希望有所收获。
SQL lite library for labview you can use these vis to operator the sqllite
python库。 资源全名:prepared_properties-1.0.2.tar.gz
fluent-plugin-mysql-prepared-statement, 的插件 流利的插件mysql准备语句查询 安装 td-agent(Linux) /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mysql-prepared-statement td-agent(Mac...
以前发的一个版本是在1.6版本上做的,很多人发现在1.6以上的版本运行都报错,经过查阅资料,得知1.6以上的版本将摄像头初始化的功能已经封装好了,所有在1.6以上的版本初始化后再录制会报错"prepared failed",将初始...
4A免费策划:奥美-Prepared for APP.pptx
java中PreparedStatement和Statement的区别
我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下两个问题: ...Many of the more mature databases support the concept of prepared statements. What are they? They can be thought
jsp网上购物,经典例子,大家可以参考 用到struts hibernate 用MVC模式
prepared_data_prepared
本文详细讲述了PDO防注入原理分析以及使用PDO的注意事项,分享给大家供大家参考。具体分析如下: 我们都知道,只要合理正确使用PDO,可以...Many of the more mature databases support the concept of prepared stateme
prepared_data_more_prepared
An object that registers to be notified of events that occur on PreparedStatements that are in the Statement pool.
Prepared Statement Spy-这将包装一个Prepared Statement实例并监视setter调用,以使您可以使用原始SQL中预先格式化的参数来检索SQL。 DDTFixture 问题是该形式的代码: final Connection connection = ...
PreparedStatement prepared_statement = connection.prepareStatement( "SELECT name, price FROM products WHERE id = ?" ); prepared_statement.setInt(1, v_id); ResultSet result_set = ...
prepared_data
greenplum java 驱动。版本:5.1.4. greenplum官方的驱动。 greenplum是postgresql集群支持。
资源分类:Python库 所属语言:Python 资源全名:evdev_prepared-0.2.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059