June 2018
Intermediate to advanced
408 pages
11h 23m
English
Inserting a large amount of data into a database is typically done by preparing an INSERT statement and executing that statement multiple times. This increases the number of JDBC calls and impacts the performance. To reduce the number of JDBC calls and improve the performance, you can send multiple queries to the database at a time by using the addBatch method of the PreparedStatement object.
Let's look at the following example:
PreparedStatement ps = conn.prepareStatement("INSERT INTO ACCOUNT VALUES (?, ?)");for (n = 0; n < 100; n++) { ps.setInt(accountNumber[n]); ps.setString(accountName[n]); ps.executeUpdate();}
In the preceding example, PreparedStatement is used to execute an INSERT statement multiple ...
Read now
Unlock full access