- 浏览: 2105919 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
无心流泪wan:
private static final Log log = ...
log4j Category.callAppenders Block -
yjxa901:
博主好: http://www.java.net/down ...
jdk debug -
aptech406328627:
大神,请接收我的膜拜吧,纠结了两天的问题,就这么让你给解决了 ...
java.lang.reflect.MalformedParameterizedTypeException -
xukunddp:
谢谢1楼,我也遇到,搞定了
java.lang.reflect.MalformedParameterizedTypeException -
di1984HIT:
学习了!!!!
jvmstat hsperfdata java.io.tmpdir
转载自:http://www.dbasky.net/archives/2009/04/oracleocithin.html
oracle的oci和thin区别
作者:Mike.Xu
发表于:
April 21, 2009 12:12 PM
转载时请务必以超链接形式标明文章
原始出处
和作者信息及本版权声明
。
链接:http://www.dbasky.net/archives/2009/04/oracleocithin.html
首先我们来看看官方对其解释:
Oracle provides four different types of JDBC drivers, for use in
different deployment scenarios. The 10.1.0 drivers can access Oracle
8.1.7 and higher. While all Oracle JDBC drivers are similar, some
features apply only to JDBC OCI drivers and some apply only to the JDBC
Thin driver.
JDBC OCI client-side driver: This is a JDBC
Type 2 driver that uses Java native methods to call entrypoints in an
underlying C library. That C library, called OCI (Oracle Call
Interface), interacts with an Oracle database. The JDBC OCI driver
requires an Oracle client installation of the same version as the
driver.
The use of native methods makes the JDBC OCI driver
platform specific. Oracle supports Solaris, Windows, and many other
platforms. This means that the Oracle JDBC OCI driver is not
appropriate for Java applets, because it depends on a C library.
Starting from 10.1.0, the JDBC OCI driver is available for install with
the OCI Instant Client feature, which does not require a complete
Oracle client-installation. Please refer to Oracle Call Interface for
more information.
JDBC Thin client-side driver: This is a
JDBC Type 4 driver that uses Java to connect directly to Oracle. It
implements Oracle's SQL*Net Net8 and TTC adapters using its own TCP/IP
based Java socket implementation. The JDBC Thin driver does not require
Oracle client software to be installed, but does require the server to
be configured with a TCP/IP listener.
Because it is written
entirely in Java, this driver is platform-independent. The JDBC Thin
driver can be downloaded into any browser as part of a Java
application. (Note that if running in a client browser, that browser
must allow the applet to open a Java socket connection back to the
server.)
JDBC Thin server-side driver: This is another JDBC
Type 4 driver that uses Java to connect directly to Oracle. This driver
is used internally within the Oracle database. This driver offers the
same functionality as the client-side JDBC Thin driver (above), but
runs inside an Oracle database and is used to access remote databases.
Because it is written entirely in Java, this driver is
platform-independent. There is no difference in your code between using
the Thin driver from a client application or from inside a server.
连接方式有以下几种:
Oralce provides four types of JDBC driver.
Thin Driver, a 100% Java driver for client-side use without an Oracle
installation, particularly with applets. The Thin driver type is thin.
To connect user scott with password tiger to a database with SID
(system identifier) orcl through port 1521 of host myhost, using the
Thin driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");
OCI
Driver for client-side use with an Oracle client installation. The OCI
driver type is oci. To connect user scott with password tiger to a
database with SID (system identifier) orcl through port 1521 of host
myhost, using the OCI driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:@myhost:1521:orcl", "scott", "tiger");
Note
that you can also specify the database by a TNSNAMES entry. You can
find the available TNSNAMES entries listed in the file tnsnames.ora on
the client computer from which you are connecting. For example, if you
want to connect to the database on host myhost as user scott with
password tiger that has a TNSNAMES entry of MyHostString, enter:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@MyHostString","scott","tiger");
If
your JDBC client and Oracle server are running on the same machine, the
OCI driver can use IPC (InterProcess Communication) to connect to the
database instead of a network connection. An IPC connection is much
faster than a network connection.
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@","scott","tiger");
Server-Side
Thin Driver, which is functionally the same as the client-side Thin
driver, but is for code that runs inside an Oracle server and needs to
access a remote server, including middle-tier scenarios. The
Server-Side Thin driver type is thin and there is no difference in your
code between using the Thin driver from a client application or from
inside a server.
Server-Side Internal Driver for code that runs
inside the target server, that is, inside the Oracle server that it
must access. The Server-Side Internal driver type is kprb and it
actually runs within a default session. You are already "connected".
Therefore the connection should never be closed.
To access the default connection, write:
DriverManager.getConnection("jdbc:oracle:kprb:");
or:
DriverManager.getConnection("jdbc:default:connection:");
You can also use the Oracle-specific defaultConnection() method of the OracleDriver class which is generally recommended:
OracleDriver ora = new OracleDriver();
Connection conn = ora.defaultConnection();
Note:
You are no longer required to register the OracleDriver class for
connecting with the Server-Side Internal driver, although there is no
harm in doing so. This is true whether you are using getConnection() or
defaultConnection() to make the connection.
Any user name or
password you include in the URL string is ignored in connecting to the
server default connection. The DriverManager.getConnection() method
returns a new Java Connection object every time you call it. Note that
although the method is not creating a new physical connection (only a
single implicit connection is used), it is returning a new object.
Again,
when JDBC code is running inside the target server, the connection is
an implicit data channel, not an explicit connection instance as from a
client. It should never be closed.
不难看出来:
1)从使用上来说,oci必须在客户机上安装oracle客户端或才能连接,而thin就不需要,因此从使用上来讲thin还是更加方便,这也是thin比较常见的原因。
2)
原理上来看,thin是纯java实现tcp/ip的c/s通讯;而oci方式,客户端通过native java method调用c
library访问服务端,而这个c library就是oci(oracle called
interface),因此这个oci总是需要随着oracle客户端安装(从oracle10.1.0开始,单独提供OCI Instant
Client,不用再完整的安装client)
3)它们分别是不同的驱动类别,oci是二类驱动, thin是四类驱动,但它们在功能上并无差异。
根据自己的环境情况,现说明下oci的配置方法:
A:安装oracle 的 cleint
对于oracle数据库客户端的安装,有二种选择,一是老实的用oracle数据库的安装光盘安装对应版本的oracle客户端。二是下载oracle提从的即时客户端,即时客户端是不用安装的,把下载包解压即可。
要使java web正常的通过oci驱动访问oracle,还需要客户端正确的配置一下相关变量。主要如下:
对于windows系统并使用oracle客户端时:
1. 把%ORACLE_HOME%lib加到PATH环境变量.
2. 把%ORACLE_HOME%jdbclibclasses12.jar加到CLASSPATH环境变量里.也可以把classes12.jar拷贝到resin的lib目录下。
对于linux系统并使用oracle即时客户端时:
1. 在使用resin的用户主目录下的.bash_profile文件中加入
exprot ORACLE_HOME=/opt/product/10.2.0/cleint/
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
2. 把instantclient_10_2目录下的classes12.jar拷贝到resin的lib目录下。
B; 要使得resin能正常链接oracle,必须正常的加载oracle的环境变量。为了方便我写个oci.sh脚本,大家可以下载(把里面的ORACLE_HOME修改成自己的路径),
执行脚本:root@testserver:[/home].oci.sh
C:重启resin。
resin.conf
<database>
<jndi-name>oracle</jndi-name>
<driver>
<type>oracle.jdbc.pool.OracleConnectionPoolDataSource</type>
<url>jdbc:oracle:oci8:@FX_RAC</url>
<password>fx</password>
<user>fx</user>
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>100</max-connections>
<max-idle-time>30s</max-idle-time>
</database>
发表评论
-
记录一些软件名词
2011-07-10 18:48 1007Small Matter of Programming ... -
软件工程经典理论
2011-04-04 10:40 1411之前一直在找寻谁说了那么一句软件工程中的经典理论: ... -
Merge Sql
2010-10-29 10:17 1610我们经常遇到的一个需求是,先判断数据是否存在,如果存在则更新, ... -
周爱民 我之于架构的主要观点
2010-06-26 19:27 992周爱民 北京Qcon讲座 infoq提供了视频 。 ... -
软件架构师应该知道的97件事
2010-04-29 22:30 1011转载自:http://blog.csdn.ne ... -
重新认识软件开发方法学
2010-03-30 23:35 1851一直不是很关注软 ... -
26 Hints for Agile Software Development
2009-12-05 20:36 956转载自:http://www.pmhut.co ... -
不是书评 :《我是一只IT小小鸟》
2009-10-08 11:41 814转载自:http://mindhacks.cn ... -
97_Things_Every_Programmer_Should_Know
2009-10-08 00:25 1389转载自:http://programmer.97things. ... -
97 Things Every Software Architect Should Know
2009-10-07 23:59 2137转载自:http://97-things.near-time. ... -
[软件项目管理]管理能力
2009-09-30 20:34 1261转载自:http://blogger.org. ... -
mysql 保留字
2009-07-04 15:44 2236转载自:http://www.blogjava.net/rro ... -
项目心得
2009-05-02 15:14 674这次项目因 ... -
oracle 分页
2008-12-29 22:32 1204oracle分页小结 现在又要写分页的东西,之前就写过,倒是参 ... -
数据库设计中的14个技巧(转)
2007-12-04 19:05 1172转自:作者: maXiaoKe, ...
相关推荐
李白高力士脱靴李白贺知章告别课本剧.pptx
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
C语言项目之超级万年历系统源码,可以做课程设计参考 文章参考:https://www.qqmu.com/4373.html
Jupyter-Notebook
51单片机加减乘除计算器系统设计(proteus8.17,keil5),复制粘贴就可以运行
《中国房地产统计年鉴》面板数据资源-精心整理.zip
Jupyter-Notebook
Jupyter-Notebook
毕业论文答辩ppt,答辩ppt模板,共18套
Jupyter-Notebook
《中国城市统计年鉴》面板数据集(2004-2020年,最新).zip
Python基础 本节课知识点: • set的定义 • Set的解析 • set的操作 • set的函数
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
兵制与官制研究资料最新版.zip
Jupyter-Notebook
七普人口数据+微观数据+可视化+GIS矢量资源-精心整理.zip
Support package for Hovl Studio assets.unitypackage
土壤数据库最新集.zip
Jupyter-Notebook
1991-2020年中国能源统计年鉴-能源消费量(分省)面板数据-已更至最新.zip