日期:2014-05-16  浏览次数:20391 次

jdbc 链接 oracle 的方法

Oracle provides drivers that enable users to make JDBC connections to Oracle databases. The two most common methods of connecting to Oracle databases via JDBC are the Oracle Thin JDBC driver and the Oracle OCI JDBC driver.

The Oracle Thin driver requires no software other than the driver jar file. This driver connects to Oracle databases via TCP/IP.

The Oracle OCI (Oracle Call Interface) driver requires Oracle client software to be installed on the user’s machine in order to connect to the database. This driver uses native methods and is platform specific.

The Java classes to connect to Oracle are contained in the Oracle JDBC driver jar file. For recent releases, these are numbered based on the Java version they are compiled for, such as ojdbc14.jar (for Java 1.4), ojdbc15.jar (for Java 1.5), etc. These drivers can be freely downloaded from Oracle’s site (free registration is required).

You can tell the Oracle driver which method you wish to use to connect to the database (OCI or Thin) via the JDBC connection URL. Listed below are some example connection URL formats:

Oracle JDBC Thin Driver Formats

第一种方式:推荐使用服务名连接,Oracle JDBC Thin using a Service Name:

jdbc:oracle:thin:@//<host>:<port>/<service_name>

Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE

第二种方式:适合单机的sid,Oracle JDBC Thin using an SID:

jdbc:oracle:thin:@<host>:<port>:<SID>

Example: jdbc:oracle:thin:192.168.2.1:1521:X01A

Note: Support for SID is being phased out. Oracle recommends that users switch over to using service names.

Oracle JDBC Thin using a TNSName: