← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #242975]: How do I connect SikuliX IDE to MySQL using zxJDBC

 

Question #242975 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/242975

    Status: Open => Solved

Peter Spierenburg confirmed that the question is solved:
Here is the solution:

import jarray

class classPathHacker(object):
    """Original Author: SG Langer Jan 2007, conversion from Java to Jython
    Updated version (supports Jython 2.5.2) From http://glasblog.1durch0.de/?p=846
    
    Purpose: Allow runtime additions of new Class/jars either from
    local files or URL
    """
    import java.lang.reflect.Method
    import java.io.File
    import java.net.URL
    import java.net.URLClassLoader
    
    def addFile(self, s):
        """Purpose: If adding a file/jar call this first
        with s = path_to_jar"""
        # make a URL out of 's'
        f = self.java.io.File(s)
        u = f.toURL()
        a = self.addURL(u)
        return a
 
    def addURL(self, u):
        """Purpose: Call this with u= URL for
        the new Class/jar to be loaded"""
        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("C:\Program Files\Sikuli\libs\mysql-connector-java-5.1.26-bin.jar")

from com.ziclix.python.sql import zxJDBC
db = zxJDBC.connect("jdbc:mysql://localhost/core", "xxx", "xxx", "com.mysql.jdbc.Driver", CHARSET='iso_1')

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.