The actual operating environment is: use Jython to link the Oracle database in Eclipse+pydev. The method has two, as shown below. (Note: the. jar file path that will be used is added to the system variable Classpath)
One:
Note: Use the Ojdbc.jar library
From Oracle.jdbc.driver import Oracledriver
From java.sql import DriverManager
def Connect (host, port, sid, User, password):
Driver = Oracledriver ()
Drivermanager.registerdriver (Driver)
Connection = "jdbc:oracle:thin:@%s:%s:%s"% (host, port, SID)
conn = Drivermanager.getconnect (connection, user, password)
stmt = Conn.createstatement ()
RSet = Stmt.executequery ("SELECT * FROM table1")
while (Rset.next ()):
Print rset.getstring (1)
Stmt.close ()
Two:
Note: Use Zxjdbc.jar to conform to the Python DB API specification.
From Com.ziclix.python.sql import Zxjdbc
Def connect ():
Driver = "Oracle.jdbc.driver.OracleDriver"
url = "jdbc:oracle:thin:@%s:%s:%s"% (host, port, SID)
conn = zxjdbc.connect (URL, user, password, driver)
cur = conn.cursor ()
Cur.execute ("SELECT * from Table2")
For data in Cur.fetchall ():
Print data
Cur.close ()
Conn.commit ()
Conn.close ()