需要的准备工作
下载
根据自己的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 OracleDriverfrom javasql import DriverManagerdef 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 conndef doStuff(conn):stmt = conncreateStatement()rset = stmtexecuteQuery(SELECT banner FROM sysv_$version)while (rsetnext()):print rsetgetString()stmtclose()if __name__ == __main__:un = ebcpw = abcsid = abchost = port = conn = connect(un pw sid host port)doStuff(conn) C:\jython>jython \tmp\orapyOracle Database g Enterprise Edition Release biPL/SQL Release ProductionCORE ProductionTNS for HPUX: Version ProductionNLSRTL Version Production
然后用jython自己封装的dbexts库
最后编辑一个名为dbextsini的文件保存到c:\jython\lib
[default]name=mysqltest[jdbc]name=oraurl=jdbc:oracle:thin:@::abcuser=ebcpwd=abcdriver=oraclejdbcdriverOracleDriverdatahandler=comziclixpythonsqlhandlerOracleDataHandler进入jython>>> from dbexts import dbexts>>> oracon = dbexts(ora c:\jython\lib\dbextsini)>>> oraconisql(SELECT * FROM v$version)BANNEROracle Database g Enterprise Edition Release biPL/SQL Release ProductionCORE ProductionTNS for HPUX: Version ProductionNLSRTL Version Production rows affected