Java Query Oracle database Cluster Connection string

Source: Internet
Author: User
Tags dedicated server oracle database stringbuffer

Event: The report interface database was suddenly unable to connect, resulting in an inability to count operations properly. Exception information: Io exception: Got minus one from a read call analysis: The database address and its configuration information are changed, after the query that the database adjusted to the cluster working mode. Results: 1. Modify the normal JDBC connection string to work in a cluster. 2. The JDBC jar file in the interface is not suitable for cluster work. Thinking width: 1. JDBC jar file Selection, Classes12 What the hell is this thing? The first time to hear very faint, in fact, is the Oracle database from the JDBC, full name Classes12.jar. The Master is so fooled! Common JDBC JAR Information

Serial number JDBC Driver package JDK 1.4 JDK 1.5 JDK 1.6 single-instance database cluster database Class.forName

1 Oraclejdbcdriver9i.jar support Support does not support Oracle.jdbc.OracleDriver

2 Classes12.jar (Oracle 92i) Support Support support does not support Oracle.jdbc.OracleDriver

3 Ojdbc14.jar (Oracle 92i) Support Support support does not support Oracle.jdbc.OracleDriver

4 Classes12.jar (Oracle 10G) support supporting support support Oracle.jdbc.OracleDriver

5 Ojdbc14.jar (Oracle 10G) support supporting support support Oracle.jdbc.OracleDriver

6 Ojdbc5.jar does not support support support support without class.forname loading

7 Ojdbc6.jar does not support unsupported support support without class.forname loading

Serial number 1:oraclejdbcdriver9i.jar This is my usual JDBC driver, this time the perpetrator! Unknown origin, Hukou (MANIFEST. MF) content is empty, preliminary analysis for the oracle92i ERA products. Serial number 2, 3: Tie out the same gate, all for oracle92i, home address: Oracle/jdbc/libclasses12.jar account information: specification-title: Oracle JDBC Driver classes For use with JDK1.2 and JDK1.3 "specification-version: Oracle JDBC Driver version-9.0.2.0.0" Ojdbc14.jar account information: Specificat Ion-title: "Oracle JDBC Driver classes for use with JDK1.4" specification-version: "Oracle JDBC Driver version-9.0.2.0.0" The biggest difference between the product of serial number 4,5:oracle 10G and Oracle 92i is the support for cluster queries. Serial number 6,7:ojdbc5.jar support JDK 1.5, support JDBC 3.0 Ojdbc6.jar support JDK 1.6, support JDBC 4.0 both without executing class.forname ("oracle.jdbc.OracleDrive R "); Direct Drivermanager.getconnection (URL, USER, PWD); It's OK. If the project supports JDK1.4 only, do not move, select the choice of serial number 4, 5. If the project supports JDK1.5 above the recommended serial number 6, 7 study the new features.

2. Cluster working mode connection string ... Carefully select a property other than the connection. Lazy paste down the code!

StringBuffer url = new StringBuffer (); Url.append ("jdbc:oracle:thin:@ description= (address_list ="); Url.append ("( Address= (PROTOCOL=TCP) (host=192.168.31.9) (port=1521)); Continue to append cluster information to your own situation, in the following format//bf.append ("Address=" (protocol= TCP) (host=10.37.27.112) (port=1521)); Url.append ("(Load_balance=yes)"); Load_balance=yes; Indicates whether the load is balanced Url.append (")"); Address_list End Url.append ("(Connect_data ="); Url.append ("(server = Dedicated)");//server = dedicated; represents a dedicated server mode. Can remove Url.append ("(SERVICE_NAME=WANGJJ)"); The database service name Url.append ("(Failover_mode ="); Url.append ("(type=session)");//type = Session indicates that when an instance of a connected conversation fails, The system automatically switches the session to another available instance, and the foreground application does not need to initiate the connection again, but the SQL that the session is executing requires the Url.append ("(Method=basic)") to be executed again; Method = Basic Indicates that the initial connection is connected to a contact, and 彵 also has an option of preconnect, which indicates that all the contacts in the initial connection Url.append ("(retries=5)"); Retries Retry Count Url.append ("(delay=15)"); DELAY retry delay Unit is seconds url.append (")"); Failover_mode End Url.append (")"); Connect_data End Url.append (")"); Description End

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.