简体   繁体   English

从sql server获取使用jdbc成功批量插入的行数

[英]Get row count of successful bulk insert using jdbc from sql server

I have Java code to bulk-insert tab file to SQL Server. 我有Java代码批量插入选项卡文件到SQL Server。 I want to get the count of how many records were inserted. 我想知道插入了多少条记录。 I tried using @@rowcount but I'm getting an error that "Statement did not return a result set". 我尝试使用@@ rowcount但是我收到一条错误“Statement没有返回结果集”。 If I run the bulk insert statement in management studio, I can get the count. 如果我在管理工作室中运行批量插入语句,我可以得到计数。

Statement stmt = sqlConnection.createStatement();         
ResultSet rs = stmt.executeQuery ("BULK INSERT schema1.table1 FROM 'd:\temp1\file1.tab' SELECT @@rowcount");

Is there any way to get the inserted count? 有没有办法获得插入计数?

I'm not familiar with SQL Server but it seems like you'll want to issue an executeUpdate instead of an executeQuery 我不熟悉SQL Server,但似乎你想要发出executeUpdate而不是executeQuery

Statement stmt = sqlConnection.createStatement();         
int insertedRowCount = stmt.executeUpdate("BULK INSERT schema1.table1 FROM 'd:\temp1\file1.tab'");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM