문제

I have SQL statements as follows:

INSERT INTO PERSON(PERSON_ID, YEAR_OF_BIRTH) VALUES (1, 0);
UPDATE PERSON SET PERSON_ID=2;

How can I execute such type of SQL commands contained successively in a single file? I need to execute this SQL file in the Java code.

Thanks.

도움이 되었습니까?

해결책

Construct an sql statement with both the queries (INSERT and UPDATE) using PreparedStatement and executes executeBatch which is according to the documentation Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts like

preparedStatement.executeBatch();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top