Install Connexion python/Oracle via ojdbc

#ok : avril 2020

1 pré requis

install pip si besoin

# sudo apt install python3-pip

# apt install python-jpype
# pip3 install jaydebeapi

informations

https://pypi.org/project/JayDeBeApi/

Télécharger

le fichier driver: ojdbc8.jar

https://www.oracle.com/database/technologies/jdbc-ucp-122-downloads.html

(Compte oracle requis)

Exemple de code

# bout de code python

import jpype
import jaydebeapi
JAR = ‘/PATH/TO/ojdbc8.jar’
jpype.startJVM(jpype.getDefaultJVMPath(), ‘-Djava.class.path=’+JAR )
cnx = jaydebeapi.connect(‘oracle.jdbc.driver.OracleDriver’, ‘jdbc:oracle:thin:user/pass@server:1521/dbname’)


rq= « select 1+2 from dual »
crs= cnx.cursor()
crs.execute(rq)
dr= crs.fetchone()
print(dr[0])
crs.close()
cnx.close()

requete oracle :Table/Champ

Sur une bd Oracle

  • Recherche d’un champ à partir d’un motif
Select TABLE_NAME, COLUMN_NAME from USER_TAB_COLUMNS where COLUMN_NAME like '%'
  •  Recherche d’une table à partir d’un motif
SELECT * FROM user_tables where table_name like '%'

Sur Sql Server

 

select TB.name [table], C.name [champ], T.name [type],
from sysobjects as TB
join syscolumns as C on TB.id=C.id
join systypes as T on C.xtype=T.xtype
where    TB.xtype='U'
and     T.name like '%'
order by TB.name, C.name