Home Database Mysql Tutorial sql2005 批量更新问题的解决方法

sql2005 批量更新问题的解决方法

Jun 07, 2016 pm 06:05 PM
Batch update

这些天因为有数据割接的需求,于是有要写关于批量更新的程序。我们的数据库使用的是SQLSERVER2005,碰到了一些问题来分享下。

首先注意Statement 和PreparedStatement的问题
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
用Statement的好处就是每次可以直接传一个SQL语句进去,不用管那么多。可是在数据量比较大的时候,应该会对效率有影响。不建议使用。
PreparedStatement ps = cn.preparedStatement(sql);
{
 ps.setXXX(1,xxx);
 ...
 ps.addBatch();
}
ps.executeBatch();
PreparedStatement是会预编译的,只要一条SQL,不断动态设值,然后addBatch(),在数据量大的时候比较好,非常建议使用。
还有就是JDBC的驱动问题,很多同志可能还是在用2000的驱动呢,没有用批量更新的程序没有多大问题,可是一旦用了批量更新,出现很多问题,
反正数据库很卡,慢。还可以更新不了哦。
我强烈建议大家更新JDBC驱动。
但是如果出现
SQLServerException: sp_cursoropen/sp_cursorprepare: 该语句参数只能是一个批或带有单个 SELECT 语句的存储过程,且不带 FOR BROWSE、COMPUTE BY 或变量赋值。
应该就是JDBC的版本问题,1.0的驱动有这个问题,好像不支持批量更新,我建议大家使用1.2
我测试过了,完全没有问题!
提供一些数据连接参数
jdbc.driverClassName:com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url:jdbc:sqlserver://127.0.0.1:1444;databaseName=fax;selectMethod=cursor;
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Steps and precautions for implementing batch updates using Oracle stored procedures Steps and precautions for implementing batch updates using Oracle stored procedures Mar 08, 2024 pm 04:12 PM

Title: Steps and Precautions for Implementing Batch Updates by Oracle Stored Procedures In Oracle database, stored procedures are a set of SQL statements designed to improve database performance, reuse code, and enhance security. Stored procedures can be used to update data in batches. This article will introduce how to use Oracle stored procedures to implement batch updates and provide specific code examples. Step 1: Create a stored procedure First, we need to create a stored procedure to implement batch update operations. The following is how to create a stored procedure

Application cases of Oracle stored procedure batch update in data processing Application cases of Oracle stored procedure batch update in data processing Mar 08, 2024 am 10:24 AM

Application cases of Oracle stored procedure batch update in data processing In actual data processing, we often need to update a large amount of data in the database. Oracle database provides the function of stored procedures, which can effectively handle these large batch data update operations and improve data processing efficiency and performance. In this article, we will introduce the application case of batch update of Oracle stored procedures and provide specific code examples to help readers better understand and use this function. Case Background Suppose we have a

The tacit cooperation between Vue and Excel: how to achieve batch update and import of data The tacit cooperation between Vue and Excel: how to achieve batch update and import of data Jul 22, 2023 pm 09:03 PM

The tacit cooperation between Vue and Excel: How to realize batch update and import of data Introduction: With the rapid development of information technology, Excel tables, as a popular data management tool, are widely used in various industries and fields. At the same time, Vue is also widely popular as a flexible and efficient front-end development framework. This article will introduce how to achieve batch update and import of data through the tacit cooperation of Vue and Excel. To help readers understand better, we will give code examples. Implement data batch update: in V

How to perform bulk insert update operations in Hibernate? How to perform bulk insert update operations in Hibernate? Aug 27, 2023 pm 11:17 PM

In this article, we will see how to perform bulk insert/update in Hibernate. Whenever we execute a sql statement, we do it by making a network call to the database. Now, if we have to insert 10 entries into the database table, then we have to make 10 network calls. Instead, we can optimize network calls by using batch processing. Batch processing allows us to execute a set of SQL statements in a single network call. To understand and implement this, let us define our entity − @EntitypublicclassParent{@Id@GeneratedValue(strategy=GenerationType.AUTO)

Efficient combination of Vue and Excel: how to achieve batch update and import of data Efficient combination of Vue and Excel: how to achieve batch update and import of data Jul 21, 2023 pm 10:00 PM

Efficient combination of Vue and Excel: How to achieve batch update and import of data. With the continuous development of web applications and the increasing amount of data, we often encounter situations where we need to update and import data in batches. As a widely used spreadsheet tool, Excel has powerful data processing and import and export functions, and has become one of our first choice tools for processing large amounts of data. This article will introduce how to use Vue and Excel to implement batch update and import of data to improve the efficiency of data processing. First, we need

How to solve database update performance problems in Java development How to solve database update performance problems in Java development Jun 29, 2023 pm 01:00 PM

How to solve database update performance issues in Java development Summary: With the increase in data volume and business changes, database update performance issues have become a major challenge in Java development. This article will introduce some common methods and techniques to solve database update performance problems. Keywords: Java development, database, update performance issues, solutions Introduction: In most Java applications, the database plays an important role. The performance of the database directly affects the response speed and stability of the application. In actual development, the number

Batch update method in MySQL Batch update method in MySQL Jun 15, 2023 pm 11:36 PM

MySQL is a widely used relational database management system that provides many effective data manipulation methods. When a large amount of data needs to be updated, the batch update method can be used to improve efficiency. This article will introduce the batch update method in MySQL. 1. What is batch update? Batch update refers to updating multiple data rows through one SQL statement. Compared with the method of updating one row at a time, batch update can effectively reduce the load of the database and network transmission time, and improve the efficiency and speed of data operations. 2. Implementation method of batch update

Oracle stored procedure batch update implementation method Oracle stored procedure batch update implementation method Mar 08, 2024 pm 12:27 PM

Title: Oracle stored procedure batch update implementation method In Oracle database, using stored procedures to batch update data is a common operation. Batch updates can improve the efficiency of data processing, reduce frequent access to the database, and also reduce the complexity of the code. This article will introduce how to use stored procedures to update data in batches in Oracle database, and give specific code examples. First, we need to create a stored procedure that will implement the function of updating data in batches. under

See all articles