when using jython 2.1, i was surprised to see that the commit was really done only when the connection is release :
Look at this code :
from oracle.jdbc.driver import OracleDriver
from java.sql import DriverManager
from java.sql import SQLException
#from java.lang import Integer
from java.lang import Boolean
def connect(un, pw, sid, host, port):
driver = OracleDriver()
connection = "jdbc:oracle:thin:@%s:%s:%s" % (host, port, sid)
conn = DriverManager.getConnection(connection, un, pw)
def populate(conn, begin_row=0, batch_size=100, batch_count=100):
#print "Before prepare"
pstmt = conn.prepareStatement("insert into scm_data(id,msisdn,iccid,imsi,persoId,firstSwitch,capName,capValue) values (?,?,?,?,?,?,?,?)");
for i in range(batch_count):
for j in range(batch_size):
#print "Before set"
#print "before executeBatch"
rows = pstmt.executeBatch()
print "Inserted %d lines" % len(rows)
print "Commited %d lines" % nbRows
print "Batch insert %d lines in : %3.2f sec" % (nbRows,
time.time() - t0)
except SQLException, e:
print "ERROR !"
if __name__ == "__main__":
un = 'scott'
pw = 'tiger'
sid = 'ome1'
host = 'localhost'
port = '1522'
conn = connect(un, pw, sid, host, port)
print "Connected as %s on %s:%s:%s" % (un,host,sid,port)
In the populate() procedure you have a commit every batch_size.
I was surprised to see that it does not work
The commit is not taken into account and is done only in the conn.close()
If you put in commentary the conn.close() line, nothing is inserted in the table which is not the normal behaviour
I did many test with a DBA to understand and :
- there is only a commit in the Oracle trace at the end with the conn.close()
- this code of course work very well in pure java
What's wrong ? I don't see any reference to this type of error
Thanks for your help,