我的SQL语句如下:
INSERT INTO PERSON(PERSON_ID, YEAR_OF_BIRTH) VALUES (1, 0);
UPDATE PERSON SET PERSON_ID=2;
如何在单个文件中连续执行此类SQL命令?我需要在Java代码中执行这个SQL文件。
感谢。
答案 0 :(得分:1)
使用sql
构建包含查询(INSERT和UPDATE)的PreparedStatement
语句,并根据documentation executeBatch
执行Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts
像
preparedStatement.executeBatch();