Solution for SQL Server batch update problem

Source: Internet
Author: User

The problems of Statement and PreparedStatement
Statement sm = cn.createstatement ();
Sm.addbatch (SQL1);
Sm.addbatch (SQL2);
...
Sm.executebatch ()
The advantage of using statement is that each time you can directly pass a SQL statement to go in, do not care so much. However, when the volume of data is relatively large, it should have an impact on efficiency. Not recommended for use.
PreparedStatement PS tutorial = cn.preparedstatement (SQL);
{
Ps.setxxx (1,XXX);
...
Ps.addbatch ();
}
Ps.executebatch ();
PreparedStatement will be precompiled, as long as a SQL, constantly dynamically set the value, and then Addbatch (), in the large amount of data when relatively good, very recommended.
There is the driving problem of JDBC, many comrades may still be in the driver with 2000, not with the batch update program does not have much problem, but once the batch update, there are many problems,
Anyway the database tutorial is very card-slow. Also can not update oh.
I strongly recommend that you update the JDBC driver.
But if it appears
Sqlserverexception:sp_cursoropen/sp_cursorprepare: This statement parameter can only be one batch or stored procedure with a single SELECT statement, and will not be assigned with a for BROWSE, COMPUTE by, or variable.
Should be the version of JDBC Problem, 1.0 of the driver has this problem, as if not support batch update, I recommend that you use 1.2
I've tested it, and there's no problem at all!
Provides some data connection parameters
Jdbc.driverClassName:com.microsoft.sqlserver.jdbc.SQLServerDriver
Jdbc.url:jdbc:sqlserver://127.0.0.1:1444;databasename=fax;selectmethod=cursor;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.