JDBC Study Notes-jdbc Performance Optimization

Source: Internet
Author: User
Tags manage connection

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 {

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.