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:
jdbc:oracle:thin:@<TNSName>
Example: jdbc:oracle:thin:@GL
Note: Support for TNSNames was added in the driver release 10.2.0.1
Oracle JDBC OCI Driver Format
jdbc:oracle:oci:@<database_name>
Example: jdbc:oracle:oci:@HR
The Oracle JDBC driver provides properties that can be specified when connecting to the database. Listed below are some examples of these properties.
To specify properties in the JDBC connection, you can use a Java Properties object, and pass that object into the JDBC getConnection method. For example:
java.util.Properties info = new java.util.Properties();
info.put(“internal_logon”, “sysdba”);
Connection conn = DriverManager.getConnection (url, info);
Connection Properties
internal_logon: Use this property to connect as a sysoper or sysdba role. When using this property, the user and password properties must be included in the properties object. For example:
Properties props = new Properties();
props.put(“user”, “scott”);
props.put(“password”, “tiger”);
props.put(“internal_logon”, “sysoper”);
Connection conn = DriverManager.getConnection (url, props);
defaultRowPrefetch: Oracle JDBC drivers allow you to set the number of rows to prefetch from the server while the result set is being populated during a query. Prefetching row data into the client reduces the number of round trips to the server. A typical value for this property is 10.
defaultBatchValue: Oracle JDBC drivers allow you to accumulate inserts and updates of prepared statements and send them to the server in batches once it reaches a specified batch value. This feature reduces round trips to the server. Use the value 1 if you don’t want to use this feature.
processEscapes: “false” to disable escape processing for statements (Statement or PreparedStatement) created from this connection. Set this to “false” if you want to avoid many calls to Statement.setEscapeProcessing(false);. This is espcially usefull for PreparedStatement where a call to setEscapeProcessing(false) would have no effect. The default is “true”.
No related posts.
相关推荐
JDBC连接Oracle数据库常见问题及解决方法
主要介绍了Java使用Jdbc连接Oracle执行简单查询操作,结合实例形式详细分析了java基于jdbc实现Oracle数据库的连接与查询相关操作技巧,需要的朋友可以参考下
使用JDBC连接Oracle数据库使用JDBC连接Oracle数据库
NULL 博文链接:https://joinyo.iteye.com/blog/1947696
如果编程人员要在一个表中查找许多行,结果中的每个行都会查找其他表中的数据,最后,编程人员创建了独立的UPDATE命令来成批地更新第一个表中的数 据。...本文将为大家介绍通过JDBC连接Oracle数据库的十大技巧。
从远程oracle数据库取数据是乱码,因为远程oracle字符集为AMERICAN_AMERICA.US7ASCII 本地oracle字符集为SIMPLIFIED CHINESE_CHINA.ZHS16GBK 所以是乱码,解决办法请下载文档 多谢 因为要下载其他资源无分 多多...
jdbc连接oracle jar包 Java JDBC连接Oracle 11g的jar包
JDBC连接ORACLE数据库 源码
jdbc连接oracle简单示例(环境为eclipse+oracle)
通过JDBC连接oracle数据库的十大技巧
JDBC连接Oracle测试 package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DB { private static Connection conn; private static ...
JDBC连接oracle数据库
JDBC连接Oracle数据库的代码和编写JDBC的经验
jdbc连接oracle,执行存储过程,带数据库存储过程,代码是详细的源码,读取配置文件,连接jdbc,执行存储过程。
java中jdbc连接oracle代码及jar包
JDBC连接oracle和mysql的jar包。JDBC连接oracle和mysql的jar包。JDBC连接oracle和mysql的jar包。
Flink JDBC Connector 支持Oracle , Flink 1.13.6 支持Oracle 11.2.0.4
【技术篇】JDBC连接ORACLE数据库之方法,方便新人来使用,适合新人入门
关于JDBC连接oracle数据库的步骤实例,新手可以借鉴,第一步加载驱动的时候可以用DriverManager或者Class.forName,下面注释掉的都是正确的代码,新手可以看看,高手勿喷
JDBC连接oracle数据库的测试,每隔20s连接一次后断开,并将连接时间、耗时和连接结果输入一个txt文件。用于测试数据库的稳定性