ojdbc8.jar
3.97MB

1. Download oracle jdbc thin driver at oracle site.

use the ojdbc8.jar from sqlcl. because i installed sqlcl.

path : /home/pi/Oracle/sqlcl/lib/ojdbc8.jar

2. EDIT TO JAVA_HOME 

nano ~/.bashrc

add the below sentence.

export JAVA_HOME="/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt"

export PATH=$PATH:$JAVA_HOME/bin

check display through export command.

3. install pandas, jaydebeapi, jpype

sudo apt-get install python-pandas

sudo pip install jaydebeapi

sudo pip install jpype1

3. create jdbc_orcle.py

import os

import sys

import jpype

import jaydebeapi as jp

import pandas.io.sql as pd_sql

from pandas import DataFrame

# JAVA_HOME이 설정되어 있지 않을 경우

if("JAVA_HOME" not in os.environ):

  os.environ["JAVA_HOME"] = "[JAVA_HOME path]"

# oracle jdbc 파일 경로 및 class 경로 설정

JDBC_Driver = '[jdbc Driver path]/ojdbc6.jar'

jar = r'[jdbc Driver path]/ojdbc6.jar'

args = '-Djava.class.path=%s' % jar

# 환경 변수 출력

print('Python Version : ', sys.version)

print('JAVA_HOME : ', os.environ["JAVA_HOME"])

print('JDBC_Driver Path : ', JDBC_Driver)

print('Jpype Default JVM Path : ', jpype.getDefaultJVMPath())

# java class path 설정

jpype.startJVM(jpype.getDefaultJVMPath(), args)

# oracle 접근

conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:user/password@DB_HOST_IP:1521:DB_NAME')

cur = conn.cursor()

# Select Query 실행

sql = "SELECT * FROM TEST"

pd_sql.execute(sql, conn)

df = pd_sql.read_sql(sql, conn, index_col = None)

print df.head()
jpype.shutdownJVM()

블로그 이미지

희망잡이

,