By Reducing the execution time of a JDBC Program, we can improve its performance. The execution time of a JDBC program depends on the Following factors:
- The driver used to connect to the database will influence the execution time. Each driver will exhibit different performance and hence, selecting a good driver that gives optimum performance will improve the performance of a JDBC program.
- setFetchSize() method of statement interface is useful to tell the driver how many rows at a time to be fetched from the database. By increasing the number of rows to be retrieved at a time, it is possible to improve the performance of a JDBC program.
- Sometimes PreparedStatment inteface can be used in place of Statement interface for improving the performance.
Affect of PerparedStatement:
Using the PreparedStatement in place of Statement Interface will improve the performance of a JDBC program.
When a SQL Statement is sent to database, the following tasks are performed:
- The SQL Statement's Syntax should be verified to know whether it is correct or not. The SQL statement is divided into small pieces called "tokens". These tokens are also verified to know whether they are in SQL format or not.
- Then another verification is done to know whether the table or view mentioned in the statement exists or not.
On the Other hand if we use preparedStatement, it does parsing only once.
This saves time and hence PreparedStatement offers better Performance.