11 Ağustos 2021 Çarşamba

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ız. OracleDataSource 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();

22 Mayıs 2020 Cuma

Oracle NoSQL Database

Giriş
Açıklaması şöyle.
It is worth nothing that the Oracle's flagship database and their NoSQL one are separate products.

9 Eylül 2019 Pazartesi

Java OracleCallableStatement Arayüzü

cosntructor
Şöyle yaparız.
oracle.jdbc.OracleConnection connection = ...;
OracleCallableStatement callableStatement = (OracleCallableStatement) connection
  .prepareCall("{call bss_acc.ACC_STATEMENT(?,?,?,?)}");

4 Eylül 2019 Çarşamba

TO_DATE Metodu

Giriş
İmzası şöyle. String parametre Date'e çevrilir. TO_CHAR metodu Date'i string'e çevirir.
TO_DATE( date_string, format_model, nls_params )
Açıklaması şöyle.
TO_DATE function just converts string to date
Örnek
Şöyle yaparız.
TO_DATE ('10-AUG-2016')
Örnek
Elimizde '20190801' olsun. Sadece ay kısmını almak için şöyle yaparız.
select extract(month from to_date(ID_BB_SECURITY, 'YYYYMMDD')) from BT_EXPORT
MM - Ay Numarası
Örnek
Şöyle yaparız.
select employee_id from employee
 where employee_date_hired > to_date('31-12-1995','DD-MM-YYYY')
Ay numarası yerine ay ismi verilmez. Şu kod yanlış.
select * from   emp_tasks
where  TASK_START_DATE > to_Date('30-MAR-18','DD-MM-YYYY');
Örnek
Şöyle yaparız.
TO_DATE(PHOTO_ACCEPTENCE_DATE,'DD-MM-YY')
MON - Ay İsmi
Ay isimleri NLS_DATE_LANGUAGE ve NLS_DATE_FORMAT ayarlarına bağlı. Çok güvenmemek lazım.
Örnek
Şöyle yaparız.
select employee_id from employee
 where employee_date_hired > to_date('31-DEC-95','DD-MON-YY')

27 Haziran 2019 Perşembe

ALTER TABLE

Giriş
ALTER TABLE veya DROP COLUMN sadece metadata ile ilgilidir. Açıklaması şöyle.
There are certain circumstances where dropping a column can be a meta-data-only operation. The column definitions for any given table are not included in each and every page where rows are stored, column definitions are only stored in the database metadata, including sys.sysrowsets, sys.sysrscols, etc.

When dropping a column that is not referenced by any other object, the storage engine simply marks the column definition as no longer present by deleting the pertinent details from various system tables. When a query subsequently references that table, it skips the bytes stored in each page for that column, as if the column no longer exists.

When a subsequent DML operation occurs against the table, the pages that are affected are re-written without the data for the dropped column. If you rebuild a clustered index or a heap, all the bytes for the dropped column are naturally not written back to the page on disk. This effectively spreads the load of dropping the column over time, making it less noticeable.
Örnek
Sütuna "default değer" ve "NOT NULL" vermek için şöyle yaparız.
ALTER TABLE table_name
  MODIFY (column_1 varchar2(100) DEFAULT 'some default' NOT NULL,
          column_2 varchar2(75) DEFAULT 'Some Value' NOT NULL);

25 Haziran 2019 Salı

BLOB

Örnek
Açıklaması şöyle.
Notice that the binary literal format on Oracle is different than MySQL. This is another reason that you should avoid using binary literals in SQL statements to make your Java program portable.
Şöyle yaparız.
Statement sta = con.createStatement();

// Inserting CLOB value with a regular insert statement
int count = sta.executeUpdate(
        "INSERT INTO Image"
        +" (ID, Subject, Body)"
        +" VALUES (1, '"+subject+"'"
        +", 'C9CBBBCCCEB9C8CABCCCCEB9C9CBBB')"); //Oracle format
//      +", 0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB)"); //SQL Server format
//      +", x'C9CBBBCCCEB9C8CABCCCCEB9C9CBBB')"); // MySQL format

18 Haziran 2019 Salı

TO_CHAR Metodu

Örnek
Şöyle yaparız.
Select TO_CHAR(sysdate,'dd-mm-yyyyy') from dual;