JDBC runs the SQL declaration. There are two processing interfaces. A preparedstatement,statement, general program JDBC How many still compare PreparedStatement
Just run the batch, PreparedStatement less statement
PS = conn.preparestatement (SQL);
for (int i = 0;i<10;i++) {
Ps.setstring (1, "1");
PreparedStatement Batch processing mode one
Ps.addbatch ();
}
PreparedStatement Batch processing mode two
Ps.addbatch ("Static SQL");
Ps.executebatch ();
This is a normal operation.
But putting the preparedstatement in it doesn't work. Below:
for (int i = 0;i<10;i++) {
PS = conn.preparestatement (SQL);
Ps.setstring (1, "1");
Ps.addbatch ();
}
Ps.executebatch ();
statement is suitable for loop assignment to SQL, below the code:
Statement st = Conn.createstatement ();
for (int i = 0;i<10;i++) {
St.addbatch ("Static SQL .....");
}
St.executebatch ();
This is the full statement of the normal operation.
Summary: The cause of this is
Statement st = Conn.createstatement (); It's not possible to put SQL statements here.
PS = conn.preparestatement (SQL); This must be the initial SQL statement
The JDBC batch cannot increment the SELECT statement, otherwise it throws an exception:
Java.sql.BatchUpdateException:Can not issue SELECT via Executeupdate ().
At Com.mysql.jdbc.StatementImpl.executeBatch (statementimpl.java:1007)
JDBC Batch processing ExecuteBatch