11 Ağustos 2021 Çarşamba

Maven İle Oracle JDBC Thin Driver

JDBC Thin Driver vs OCI
Açıklaması şöyle. Yani Java kullanıyorsak JDBC Thin Driver yeterli.
Oracle provides four types of drivers for their database, but I'll only enumerate the two you asked about.

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'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 ...
Maven
ojdbc "Oracle JDBC Driver" anlamına gelir

ojdbc11
Örnek
Şöyle yaparız
<dependency>
  <groupId>com.oracle.database.jdbc</groupId>
  <artifactId>ojdbc11</artifactId>
  <version>23.2.0.0</version>
</dependency>
ojdbc10
Örnek
Şöyle yaparız
Java 11
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc10</artifactId>
    <version>${oracle.version}</version>
</dependency>

Java 8
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>${oracle.version}</version>
</dependency>

Java 6
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>${oracle.version}</version>
</dependency>
ojdbc8
Java 8 içindir
Örnek
Şöyle yaparız
<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc8</artifactId>
  <version>19.7.0.0</version>
</dependency>
Şöyle yaparız
<dependency>
  <groupId>com.oracle.database.jdbc</groupId>
  <artifactId>ojdbc8-production</artifactId>
  <version>21.7.0.0</version>
  <type>pom</type>
</dependency>
ojdbc7
Java 8 öncesi içindir
Örnek 
Şöyle yaparız
<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc7</artifactId>
  <version>12.1.0.2</version>
</dependency>
Sınıflar
Bazı sınıflar şöyle 

Connection Pool
Oracle Universal Connection Pool kullanılabilir.

Universal Connection Pool - PoolDataSource Sınıfı

Giriş
Açıklaması şöyle. Yani 12c'den sonra JDBC sürücüsü de en az 12.1.0.2 olmalı
Prior to 12c (i.e., 12.1.0.1.0), UCP could work with any version of Oracle JDBC driver. With the new pool, UCP 12.1.0.2, it is dependent on Oracle JDBC driver 12.1.0.2.
Örnek
Şöyle yaparızOracleDataSource sınıfını kullanıyor
import oracle.ucp.jdbc.PoolDataSource;
import java.sql.Connection;
import java.sql.SQLException;

PoolDataSource ds = PoolDataSourceFactory.getPoolDataSource();
ds.setUser("...");
ds.setPassword("...");
ds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
ds.setURL("jdbc:oracle:thin:@exampledb?TNS_ADMIN=/msdataworkshop/creds");
Connecton con = ds.getConnection();
Örnek
Şöyle yaparız.
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();

pds.setURL(...);
pds.setUser(...);
pds.setPassword(...);
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");

//Setting pool properties
pds.setInitialPoolSize(5);
pds.setMinPoolSize(5);
pds.setMaxPoolSize(20);

Connection conn = pds.getConnection();
Şöyle yaparız.
int usedConnectionCount = pds.getBorrowedConnectionsCount();
int availableConnectionCotun = pds.getAvailableConnectionsCount();