Statement Batch Update
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Main {
public static void main(String[] argv) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial",
"root", "root");
con.setAutoCommit(false);
String table1 = "INSERT emp_sal VALUES('v',1200)";
String table2 = "DELETE FROM movies WHERE title = 'r'";
Statement st = con.createStatement();
st.addBatch(table1);
st.addBatch(table2);
int count[] = st.executeBatch();
con.commit();
con.close();
System.out.println("Successfully!");
}
}
Related examples in the same category