Java JDBCI BULK INSERT Data

Source: Internet
Author: User
Tags bulk insert sql injection

Smart insert: Batch, every 1000 commits, SQL injection (security, use soft parsing, improve efficiency)

SQL injection attacks: Simple Example

SELECT * FROM table where name= ' "+un+" ' and psw= ' "+pw+" ' ",

If any character can be entered, un casually input 12345 ' or 1=1--so that the AA will be select * from table where name= ' 12345 ' or 1=1--password

String sql = "INSERT into employee (name, city, phone) values (?,?,?)"; Connection Connection=Newgetconnection (); PreparedStatement PS=connection.preparestatement (SQL);Final intbatchsize = 1000;intCount = 0; for(Employee employee:employees) {ps.setstring (1, Employee.getname ()); Ps.setstring (2, Employee.getcity ()); Ps.setstring (3, Employee.getphone ());    Ps.addbatch (); if(++count% BatchSize = = 0) {ps.executebatch (); }}ps.executebatch (); //Insert remaining Recordsps.close (); Connection.close ();

Java JDBCI BULK INSERT Data

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.