Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize batch Update in SQLServer2005 Database

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to achieve batch updates in the SQLServer2005 database. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

How to update SQLServer2005 database in batch

First, pay attention to the problems of Statement and PreparedStatement.

Statementsm=cn.createStatement ()

Sm.addBatch (sql1)

Sm.addBatch (sql2)

...

Sm.executeBatch ()

The advantage of using Statement is that you can pass a SQL statement directly into it at a time, regardless of so much. However, when the amount of data is relatively large, it should have an impact on efficiency. Use is not recommended.

PreparedStatementps=cn.preparedStatement (sql)

{

Ps.setXXX (1meme xxx)

...

Ps.addBatch ()

}

Ps.executeBatch ()

PreparedStatement will be pre-compiled, as long as a SQL, constantly set the value dynamically, and then addBatch (), which is better when there is a large amount of data, which is very recommended.

How to update SQLServer2005 database in batch

There is also the driver problem of JDBC. Many comrades may still be using 2000 drivers. There is no big problem without batch update programs, but once batch updates are used, there will be a lot of problems.

Anyway, the database is very slow. It can not be updated.

I strongly recommend that you update the JDBC driver.

But if it shows up,

SQLServerException:sp_cursoropen/sp_cursorprepare: this statement parameter can only be a batch or a stored procedure with a single SELECT statement without FORBROWSE, COMPUTEBY, or variable assignment.

It should be the version of JDBC. The driver of 1.0 has this problem. It seems that batch updates are not supported. I suggest you use 1.2.

I've tested it, and there's no problem at all!

Provide some data connection parameters

Jdbc.driverClassName:com.microsoft.sqlserver.jdbc.SQLServerDriver

Jdbc.url:jdbc:sqlserver://127.0.0.1:1444;databaseName=fax;selectMethod=cursor

About how to achieve batch updates in the SQLServer2005 database to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report