Java programming-batch processing and execution of SQL statements

Source: Internet
Author: User

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;
}

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.