- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下方法有效,但如何收集多个 MapSqlParameterSource
并将它们全部插入一批?
new SimpleJdbcInsert(ds).withTableName(TABLENAME);
MapSqlParameterSource entry = new MapSqlParameterSource()
.addValue("id", report.queryId, Types.INTEGER)
.addValue("firstname", report.reportDate, Types.DATE)
.addValue("age", report.completionRatio, Types.INTEGER);
insert.execute(entry);
最佳答案
幸运的是,SimpleJdbcInsert
可以采用 MapSqlParameterSource
的数组(而不是列表)。所以可能如下:
List<MapSqlParameterSource> entries = new ArrayList<>();
entries.add(entry);
MapSqlParameterSource[] array = entries.toArray(new MapSqlParameterSource[entries.size()]);
insert.executeBatch(array);
关于java - 如何使用SimpleJdbcInsert和MapSqlParameterSource批量插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49239139/
我正在使用 Spring 的 SimpleJdbcInsert 类来创建实体 - 例如: final SimpleJdbcInsert insert = new SimpleJdbcInsert(da
我有一个要求,我必须在数据库中插入一行并取回 key (身份)。我想为此使用 SimpleJdbcInsert 。我正在传递 JdbcTemplate 的对象到我的 SimpleJdbcInsert和
我在服务器端使用 tomcat 和 Mysql Server 5.5。 我使用 Spring 框架进行数据库连接。 我希望能够使用 simpleJdbcInsert 向表中插入一行。如果插入由于重复而
我正在使用 springs SimpleJdbcInsert 执行 JDBC 插入并返回 2 个自动生成的键。 我使用的命令是: KeyHolder keys = insert.withTableNa
这是我写的相关代码: new SimpleJdbcInsert(dataSource) .withSchemaName("test") .withTableName("tableNam
我正在使用以下主键声明对 MySQL 表运行简单的插入查询: id BIGINT AUTO_INCREMENT NOT NULL PRIMARY KEY 出于某种原因,他们返回的键是一个 BigInt
大家早上好 我正在使用 HSQLDB 对 JUnit 项目的持久层进行单元测试。该项目使用 Spring 和 Hibernate + JPA。我正在使用 Spring 的 SimpleJdbcInse
我收到这个错误 Unable to locate columns for table 'user_models' so an insert statement can't be generated 使
我学习Spring Boot阅读《Spring in Action 5》一书。我尝试向H2嵌入式数据库插入数据。我使用SimpleJdbcInsert和executeAndReturnKey方法。 这
SimpleJdbcInsert 有一个 usingColumns(String...) 方法,您可以在其中定义插入语句中包含的列集。 但有时相反的功能是首选,例如当有一个 25 列的表和一个自动生成
我正在尝试使用 JDBC Spring 框架在 Sql Server 2008 中插入一行: 代码如下: BdClass bdclass= new BdClass(BdClass.BdConfig.C
根据 Spring 3.2 Data access docs , SimpleJdbcInsert 可用于检索自动生成的 key 。但是,我无法在下面的代码中重写 JdbcDaoSupport 的 f
我在使用 Sybase(jTDS 驱动程序)和某些数据时遇到了 SimpleJdbcInsert.executeAndReturnKey 的奇怪问题。 看下面的例子: SimpleJdbcInsert
我想一次插入多条记录,并获取每条记录的id,它是自动递增的。我正在按照以下方式进行操作,但获取更新的行数而不是生成的键,在这种情况下为 id。 public int[] addPersons(List
我正在使用 SimpleJdbcInsert 作为, SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource).with
我是一名优秀的程序员,十分优秀!