I'm having trouble returning zxJDBC errors (in specific, my connection to the MySQL appears to drop due to network issues and this is causing my program to crash/hang), but will be honest that I don't know a great deal returning .jar errors in Jython. Most of my programming experience has been limited to BASH & Perl in the past, prior to this current adventure in Jython. What I am looking to do is return all zxJDBC errors, so I can identify & write try/except handling around those that I can deal with.
Relevant code is as follows:
##########################################################
# from http://forum.java.sun.com/thread.jspa?threadID=300557
#
# Author: SG Langer Jan 2007 translated the above Java to this
# Jython class
# Purpose: Allow runtime additions of new Class/jars either from
# local files or URL
######################################################
class classPathHacker(object):
import java.lang.reflect.Method
import java.io.File
import java.net.URL
import java.net.URLClassLoader
def addFile(self, s):
f = self.java.io.File(s)
u = f.toURL()
a = self.addURL(u)
return a
def addURL(self, u):
sysloader = self.java.lang.ClassLoader.getSystemClassLoader()
sysclass = self.java.net.URLClassLoader
method = sysclass.getDeclaredMethod("addURL", [self.java.net.URL])
a = method.setAccessible(1)
jar_a = jarray.array([u], self.java.lang.Object)
b = method.invoke(sysloader, [u])
return u
tmp = classPathHacker()
tmp.addFile("/opt/sikuli/libs/mysql-connector-java-5.1.29-bin.jar")
from com.ziclix.python.sql import zxJDBC
db = zxJDBC.connect("jdbc:SERVER/DATABASE", "USER", "PASSWORD", "com.mysql.jdbc.Driver", CHARSET='iso_1')
b = db.cursor()
b.execute("SOME_SQL_CODE_GOES_HERE")
for row in b:
data = str(row)
<DO IRRELEVANT THINGS WITH SQL RETURN>
b.close()
db.close()
How would I structure the code to capture errors/exceptions?
I suspect there is some valuable information here for someone who knows enough Java to translate it to Jython.