java - I have to insert three rows in to sql server at a time -
i have insert 3 rows in sql server java @ time , not want other rows between them other threads . can that?
use java.sql.statement.addbatch(), java.sql.statement.executebatch.
more details see link
string [] queries = { "insert employee (name, city, phone) values ('a', 'x', '123')", "insert employee (name, city, phone) values ('b', 'y', '234')", "insert employee (name, city, phone) values ('c', 'z', '345')", }; connection connection = new getconnection(); statement statement = connection.createstatement(); (string query : queries) { statement.addbatch(query); } statement.executebatch(); statement.close(); connection.close();
but if have multiple threads inserting in same table might need synchronized
inserting method
synchronized details
Comments
Post a Comment