sqlserver java SQLServerBulkCopy 插入自增列

SQLServerBulkCopy
设置通过设置列映射来实现,只insert映射的列,不映射自增列,就可以自动插入自增列
确保 copyOptions.setKeepIdentity(true);

                copyOptions.setKeepIdentity(true);
                copyOptions.setBatchSize(2000);
                copyOptions.setBulkCopyTimeout(5000);
                // this is importance setting
                copyOptions.setCheckConstraints(true);
                bulkCopy.setBulkCopyOptions(copyOptions);
                SQLServerBulkCSVFileRecord fileRecord = new SQLServerBulkCSVFileRecord(
                        FileFullPath, "GBK", "\r\n", false);

                // Set the metadata for each column to be copied.
                fileRecord.addColumnMetadata(1, "rowdata", java.sql.Types.NVARCHAR, 2000, 0);
                bulkCopy.addColumnMapping("rowdata", "rowdata");

Java: how to perform batch insert with identity column using java jdbc for Sql Server

© 2021, 新之助meow. 原创文章转载请注明: 转载自http://www.xinmeow.com

0.00 avg. rating (0% score) - 0 votes
点赞