Access the Oracle database with Jython

Source: Internet
Author: User


Preparations
Download
Http://jaist.dl.sourceforge.net/sourceforge/zxjdbc/zxJDBC-2.1.tar.gz
Http://jaist.dl.sourceforge.net/sourceforge/jython/jython_installer-2.2.1.jar
Download the corresponding ojdbc version based on your JDK version.
Http://download.oracle.com/otn/utilities_drivers/jdbc/10203/ojdbc14.jar
Http://download.oracle.com/otn/utilities_drivers/jdbc/111060/lib/ojdbc5.jar
Http://download.oracle.com/otn/utilities_drivers/jdbc/111060/lib/ojdbc6.jar

Install JDK/JRE ?)
Java-jar jython_installer-2.2.1.jar installed to C:/jython2.2.1
Decompress zxjdbc. jar to C:/tmp
Copy mm. mysql-2.0.4-bin.jar to C:/tmp
C:/jython2.2.1> set classpath = C:/tmp/ojdbc5.jar; C:/tmp/zxjdbc. jar; % classpath %

Start ORACLE Server

Access Oracle in the Jython Environment
Edit file C:/tmp/ora. py
From Oracle. JDBC. Driver import oracledriver
From Java. SQL import drivermanager

Def connect (UN, PW, Sid, host, Port ):
Driver = oracledriver ()
Drivermanager. registerdriver (driver)
Connection = "JDBC: oracle: thin: @ % s: % s" % (host, port, Sid)
Conn = drivermanager. getconnection (connection, UN, PW)
Return Conn

Def dostuff (conn ):
Stmt = conn. createstatement ()
Rset = stmt.exe cutequery ("select banner from SYS. V _ $ version ")
While (rset. Next ()):
Print rset. getstring (1)
Stmt. Close ()

If _ name _ = "_ main __":
UN = 'ebc20'
PW = 'abc'
SID = 'abc'
Host = '10. 4.231.16'
Port = '000000'
Conn = connect (UN, PW, Sid, host, Port)
Dostuff (conn)

C:/jython2.2.1> Jython/tmp/ora. py
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0-64bi
PL/SQL release 10.2.0.3.0-Production
Core 10.2.0.3.0 Production
TNS For HPUX: Version 10.2.0.3.0-Production
Nlsrtl version 10.2.0.3.0-Production

Use the dbexts library encapsulated by Jython
Edit a file named dbexts. ini and save it to C:/jython2.2.1/lib.
[Default]
Name = mysqltest

[JDBC]
Name = ora
Url = JDBC: oracle: thin: @ 10.4.231.16: 1521: ABC
User = ebc20
Pwd = ABC
Driver = oracle. JDBC. Driver. oracledriver
Datahandler = com. ziclix. Python. SQL. handler. oracledatahandler

Go to Jython

>>> From dbexts import dbexts
>>> Oracon = dbexts ("ora", "C:/jython2.2.1/lib/dbexts. ini ")

>>> Oracon. iSQL ("select * from V $ version ")

Banner
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0-64bi
PL/SQL release 10.2.0.3.0-Production
Core 10.2.0.3.0 Production
TNS For HPUX: Version 10.2.0.3.0-Production
Nlsrtl version 10.2.0.3.0-Production

5 rows affected

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.