The performance of jdbc programs is mainly determined by two factors: one is the nature of the database itself, and the other is the use of jdbc application interfaces (APIS) that are relatively independent from the database. here we will talk about how to correctly use the jdbc programming interface to achieve better performance.
Major jdbc optimizations include:
1. Select the correct jdbc driver
2. Connention optimization using the Connection pool to manage Connection objects
3. Optimize the use of Statement for batch update, etc.
4. The Result is optimized to get data from the database correctly.
(1) Select the correct jdbc driver:
1 jdbc-odbc bridge
2 Local api-some java drivers
3. jdbc network protocol-pure java driver
4. jdbc local Protocol
It is best to select jdbc network protocol-java-only drivers are more efficient, but support from third-party software is required, such as the type of corba weblogic.
(2) Optimize the Connection object:
1. Set the appropriate parameter DriverManager. getConnection (String url, Properties props );
Example: Properties props = new Properties ();
Props. put ("user", "wuwei ");
Props. put ("password", "wuwei ");
Props. put ("defaultRowPrefectch", "30 ");
Props. put ("dufaultBatchValue", "5 ");
Connection con = DriverManager. getConnection ("jdbc: oracle: thin: @ hostsString", props );
The object can be optimized by setting the setDefaultRowPrefetch (int) and setDefaultBatchValue (int) parameter classes.
2. Using the connection pool, you can write a connection pool by yourself, which is flexible and easy to transplant.
The apache project developed a set of very general and very stable Object pool http://jakarta.apache.org/commons/pool.htm.
After designing your own connection pool, you can call the client to create an object.
Public Object makeObject () throws Exception {
Class. forName ("oracle. jdbc. driver. OracalDriver ");
Return DriverManager. getConnection ("url", "username", "password ");
}
Used to destroy objects
Public void destroyObject (Object obj) throws Exception {