We can insert the multiple rows into
sql server from java using the statement.executeBatch()
function. The sample program for
inserting the multiple rows are given below.
package
com.test;
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.Statement;
public
class
MultipleRowUpdateTest {
public
static
void
main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/portal","root",
"root");
Statement
stmt = conn.createStatement();
stmt.addBatch("INSERT
INTO role " +
"VALUES(5,'temp5','ROLE_ESWAR5')");
stmt.addBatch("INSERT INTO
role " +
"VALUES(6,
'temp3','ROLE_ESWAR2')");
stmt.addBatch("INSERT INTO
role " +
"VALUES(7,
'temp4','ROLE_ESWAR3')");
stmt.executeBatch();
}catch
(Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment