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;