OCI和THIN驱动程序连接与java和oracle XE之间的数据源连接有什么区别? [英] What is the difference between OCI and THIN driver connection with data source connection between java and oracle XE?
问题描述
我正在使用3路(OCI,THIN和数据源)编写以下代码来连接java和Oracle 10g XE,代码运行成功,但不知道THIN和OCI与数据源之间的区别连接。
I'm writing the below codes for connection between the java and Oracle 10g XE using 3 way(OCI, THIN and data source), the code is running successfully but don't know difference between the THIN and OCI with data source connection.
1 -
public static void main (String args[]) throws SQLException
{
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
Connection con = ods.getConnection();
System.out.println("Connected");
con.close();
}
2-
public static void main(String args[])
{
try
{
// load oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// connect using Thin driver
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
System.out.println("Connected Successfully To Oracle");
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
3 -
public static void main(String args[])
{
try
{
// load oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// connect using Native-API (OCI) driver
Connection con = DriverManager.getConnection("jdbc:oracle:oci:@","hr","hr" );
System.out.println("Connected Successfully To Oracle using OCI driver");
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
推荐答案
Oracle为他们的数据库提供了四种类型的驱动程序,但我只列举你问的两个。
Oracle provides four types of drivers for their database, but I'll only enumerate the two you asked about.
OCI 驱动程序是< a href =http://en.wikipedia.org/wiki/JDBC_driver#Type_2_Driver_-_Native-API_Driver =noreferrer> type 2 JDBC驱动程序并使用本机代码连接到数据库。因此,它只是具有本机Oracle驱动程序并且不是纯Java实现的平台上的一个选项。
The OCI driver is a type 2 JDBC driver and uses native code to connect to the database. Thus, it is only an option on platforms that have native Oracle drivers available and it is not a "pure" Java implementation.
Oracle的JDBC Thin驱动程序是类型4 使用Java套接字直接连接到Oracle的JDBC驱动程序。它直接实现了Oracle的SQL * Net TCP / IP协议。因为它是100%Java,它独立于平台,也可以从Applet运行。 (不是你应该的)
Oracle's JDBC Thin driver is a type 4 JDBC Driver that uses Java sockets to connect directly to Oracle. It implements Oracle's SQL*Net TCP/IP protocol directly. Because it is 100% Java, it is platform independent and can also run from an Applet. (not that you should)
这篇关于OCI和THIN驱动程序连接与java和oracle XE之间的数据源连接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!