需要的准備工作
下載
根據自己的jdk版本下載對應的ojdbc版本
ar
ar
安裝(需要已經安裝了jdk/jre?)
java jar jython_installerjar 安裝到C:\jython
將zxJDBCjar解壓縮到c:\tmp
將mmmysqlbinjar復制到c:\tmp
C:\jython>set CLASSPATH=c:\tmp\ojdbcjar;c:\tmp\zxJDBCjar;%CLASSPATH%
啟動Oracle服務器:
進入jython環境訪問Oracle
編輯文件c:\tmp\orapy
from oraclejdbcdriver import OracleDriver
from javasql import DriverManager
def connect(un pw sid host port):
driver = OracleDriver()
DriverManagerregisterDriver(driver)
connection = jdbc:oracle:thin:@%s:%s:%s % (host port sid)
conn = DriverManagergetConnection(connection un pw)
return conn
def doStuff(conn):
stmt = conncreateStatement()
rset = stmtexecuteQuery(SELECT banner FROM sysv_$version)
while (rsetnext()):
print rsetgetString()
stmtclose()
if __name__ == __main__:
un = ebc
pw = abc
sid = abc
host =
port =
conn = connect(un pw sid host port)
doStuff(conn)
C:\jython>jython \tmp\orapy
Oracle Database g Enterprise Edition Release bi
PL/SQL Release Production
CORE Production
TNS for HPUX: Version Production
NLSRTL Version Production
然後用jython自己封裝的dbexts庫
最後編輯一個名為dbextsini的文件保存到c:\jython\lib
[default]
name=mysqltest
[jdbc]
name=ora
url=jdbc:oracle:thin:@::abc
user=ebc
pwd=abc
driver=oraclejdbcdriverOracleDriver
datahandler=comziclixpythonsqlhandlerOracleDataHandler
進入jython
>>> from dbexts import dbexts
>>> oracon = dbexts(ora c:\jython\lib\dbextsini)
>>> oraconisql(SELECT * FROM v$version)
BANNER
Oracle Database g Enterprise Edition Release bi
PL/SQL Release Production
CORE Production
TNS for HPUX: Version Production
NLSRTL Version Production
rows affected
From:http://tw.wingwit.com/Article/program/Oracle/201311/17232.html