当前位置: 首页 > news >正文

Oracle的oci和thin的不同

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

前几天同事跑过来跟我说, 机房中的一台tomcat服务器跟oracle数据库机连接很慢,查看控制台中的hibernate日志, 基本上是一条sql出来要等个1-2秒再出第二条。但同样的程序在他自己机器上的tomcat运行,同样是连那台数据库机器,就快很多,不会出现前面的每执行1条sql就卡一次壳的情况。 
初步分析,我就想到可能是网络原因, 机房两台机器连接不畅通, 程序和机器差的原因基本可以排除, 机房的tomcat机比我们开发机要强多了, 而且程序在他的机器上运行又没有问题。于是我就劝他到机房去检查一下网络状态, 但他一时也无法进入,因为机房的管理人员不在。 
过了一会, 他告诉我问题解决了, 把数据库访问的url更换成了oci方式就好了, oci对我来说有些陌生, 我一直是用的thin,也没想过其他连接方式。对于oci我也只能想到oracle 的client中貌似是有oci什么的,当时有其他事情也没管了。 

今天有意了解一下区别,先看看thin和oci的url写法上的区别: 
jdbc:oracle:thin:@server ip: service 
jdbc:oracle:oci:@service 
看来oci的还更加简洁,ip可以省掉不写了。 

接下来再找找oci和thin的其他区别,发现有如下解释: 

引用


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是四类驱动,但它们在功能上并无差异。 
4)虽然很多人说oci的速度快于thin,但找了半天没有找到相关的测试报告。


转载于:https://my.oschina.net/u/2308739/blog/552831

相关文章:

  • 几个 vim 的块操作命令
  • Android进阶:打jar包获取assets中的资源 解决selector XML文件不能解...
  • 模拟实现兼容低版本IE浏览器的原生bind()函数功能
  • oracle中exp,imp(导入,导出)的使用详解
  • 【原创】erlang 模块之 rpc
  • Extreme交换机基本配置-账号软件升级密码配置
  • 使用mysqldump导入导出含BOLB数据的表
  • root logger默认的level是logging.WARNING
  • Prime Path
  • vim配色方案colorscheme设置
  • JAVA图形界面(GUI)之菜单
  • the difference among ios deivces
  • 随笔 2016-1-4
  • VC中的数据类型转换BSTR、char*和CString
  • contentprovider的学习实例总结
  • 【跃迁之路】【585天】程序员高效学习方法论探索系列(实验阶段342-2018.09.13)...
  • 07.Android之多媒体问题
  • happypack两次报错的问题
  • IDEA常用插件整理
  • JAVA SE 6 GC调优笔记
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • Js实现点击查看全文(类似今日头条、知乎日报效果)
  • JS实现简单的MVC模式开发小游戏
  • js数组之filter
  • OpenStack安装流程(juno版)- 添加网络服务(neutron)- controller节点
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • 盘点那些不知名却常用的 Git 操作
  • 手写双向链表LinkedList的几个常用功能
  • 智能网联汽车信息安全
  • 扩展资源服务器解决oauth2 性能瓶颈
  • ​ ​Redis(五)主从复制:主从模式介绍、配置、拓扑(一主一从结构、一主多从结构、树形主从结构)、原理(复制过程、​​​​​​​数据同步psync)、总结
  • #免费 苹果M系芯片Macbook电脑MacOS使用Bash脚本写入(读写)NTFS硬盘教程
  • (30)数组元素和与数字和的绝对差
  • (C语言)二分查找 超详细
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (完整代码)R语言中利用SVM-RFE机器学习算法筛选关键因子
  • (一)UDP基本编程步骤
  • **登录+JWT+异常处理+拦截器+ThreadLocal-开发思想与代码实现**
  • ./configure,make,make install的作用
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .cfg\.dat\.mak(持续补充)
  • .Net的C#语言取月份数值对应的MonthName值
  • .Net接口调试与案例
  • .NET下ASPX编程的几个小问题
  • @GlobalLock注解作用与原理解析
  • @value 静态变量_Python彻底搞懂:变量、对象、赋值、引用、拷贝
  • [ vulhub漏洞复现篇 ] JBOSS AS 4.x以下反序列化远程代码执行漏洞CVE-2017-7504
  • [CC2642R1][VSCODE+Embedded IDE+IAR Build+Cortex-Debug] TI CC2642R1基于VsCode的开发环境
  • [CISCN 2023 初赛]go_session
  • [CUDA手搓]从零开始用C++ CUDA搭建一个卷积神经网络(LeNet),了解神经网络各个层背后算法原理
  • [error] 17755#0: *58522 readv() failed (104: Connection reset by peer) while reading upstream
  • [Flex][问题笔记]TextArea滚动条问题
  • [HackMyVM]靶场 Quick3
  • [iOS]中字体样式设置 API