Using Jython, zxJDBC, and DBUnit

Not much time for the long post that this deserves, but here is an example of using Jython, zxJDBC, and DBUnit. This little snippet makes a JDBC connection to a JDBC database and gets all the data out of it and stores it in an XML file

from com.ziclix.python.sql import zxJDBC
from org.dbunit.database import DatabaseConnection
from org.dbunit.dataset.xml import FlatXmlDataSet

if __name__ == '__main__':
    d,u,p,v = ("jdbc:db2://172.16.21.217:50000/mh332",
               "db2inst1","db2inst1","com.ibm.db2.jcc.DB2Driver")

    db = zxJDBC.connect(d,u,p,v)
    ## you have to use this almost-undocumented __connection__ property
    conn = DatabaseConnection(db.__connection__)
    fullset =conn.createDataSet()
    FlatXmlDataSet.write(fullset,open("db2backup.xml","w"))

Leave a Reply

You must be logged in to post a comment.