Tera Mind
Tera Mind

Reputation: 263

Batch processing using PreparedStatement

Am I right when I say that I can only use 1 string sql query for batch processing using PreparedStatement in Java?

For example, this is the batch I want to process using PreparedStatement:

INSERT INTO tbl_Customer VALUES(?,?,?,?)
INSERT INTO tbl_Order VALUES(?,?,?,?,?)

Is there any way to process these statements as a batch? Sorry for my bad English.

Upvotes: 2

Views: 1051

Answers (1)

Ori Marko
Ori Marko

Reputation: 58772

You the following template:

PreparedStatement ps = null;

ps = conn.prepareStatement("INSERT INTO tbl_Customer VALUES(?,?,?,?)");
while () { 
    ...
    ps.addBatch();
}
result = ps.executeBatch();

Upvotes: 3

Related Questions