In our actual project development process, some functions may need to execute several SQL statements in the background or even execute some SQL statements in batches. If one statement is cyclically executed, I think everyone knows that this is very inefficient, especially in batch SQL, but if we aggregate the entire SQL statement into a separate SQL statement with ';' in a loop, then the execution efficiency is improved a lot.
String [] idsArray = addMenuIds. split (",");
For (int I = 0; I <idsArray. length; I)
{
SQL. append ("insert into T_USER_MENU (ID _, MENU_ID _, USER_ID _) values (S_USER_MENU.nextval ,"
Integer. parseInt (idsArray [I])
","
Integer. parseInt (userId)
");");
}
JdbcDao.exe cute (SQL. toString (). split (";"));
Execute in jdbcDao:
Public boolean execute (String [] SQL)
{
Try
{
This. getSimpleJdbcTemplate (). getJdbcOperations (). batchUpdate (SQL );
} Catch (DataAccessException e)
{
E. printStackTrace ();
Return false;
}
Return true;
}