Search code examples
mysql-connectornoclassdeffounderrorsikulisikuli-scriptsikuli-ide

Issue with connecting to MySQL database using Sikulix 2.0.5


I am currently facing a problem with Sikulix 2.0.5 on a Windows 10 operating system, with JAVA8, Python, and Jython installed. Previously, I had been using version 1.1.3 successfully, where I had built an automation script that connected to a MySQL database running on Ubuntu. The following commands allowed me to establish a normal connection and ensured correct operation:

load("zxJDBC.jar")
load("mysql-connector-java-8.0.18")
from com.ziclix.python.sql import zxJDBC
connectDrv = "com.mysql.cj.jdbc.Driver"
connectHost = "jdbc:mysql://xxx.xx.x.xxx"

In my attempt to upgrade to Sikulix 2.0.5, I am encountering difficulties connecting to my database. I found some instructions online, and I tried the following solutions:

Solution 1 (from Raiman): According to Raiman, the load() feature in Sikulix 2.0.5 no longer works as expected, as entries to the Java classpath from within a Java program are no longer allowed. The recommended approach is to set up the Java classpath and IDE start on the command line. Here's an example command:

java -cp mystuff1.jar;mystuff2.jar;. org.sikuli.ide.Sikulix ... (optional parameters)

Solution 2: Remove or comment out any load() lines in your Sikulix script that attempt to add external JAR files to the classpath.

Copy the required JDBC driver files (driverXXXXX.jar and zxJDBC.jar) to the Extensions folder of your Sikulix installation. The folder path might be similar to C:\Users\fakename\AppData\Roaming\Sikulix\Extensions.

Open a command prompt on your PC.

Change the directory to the location where the Sikulix IDE is installed. For example, if Sikulix is installed in C:\SikuliX, run the following command:

cd C:\SikuliX

Set up the Java classpath by specifying the JAR files you want to include. For example, if you have the two JDBC driver JAR files in the Extensions folder, set the classpath like this:

set CLASSPATH=.\sikulix.jar;.\Extensions\driverXXXXX.jar;.\Extensions\zxJDBC.jar

Start the Sikulix IDE by running the following command:

java org.sikuli.ide.Sikulix

However, when I tried both solutions, I encountered the following error:

[error] script [ sikulitemp-10261534140358839691 ] stopped with error in line 7 [error] java.lang.NoClassDefFoundError ( java.lang.NoClassDefFoundError: Could not initialize class com.ziclix.python.sql.zxJDBC ) [error] --- Traceback --- error source first line: module ( function ) statement 7: main ( ) from com.ziclix.python.sql import zxJDBC [error] --- Traceback --- end --------------

I would greatly appreciate any help.


Solution

  • After researching the last few days I found that SikuliX version 2.0.5 has a problem with zxJDBC.

    Specifically in a question to RaiMan he replied that:

    This might be a problem with the now bundled Jython 2.7.2... but currently I do not have a solution for you, because the 2.0.5 cannot be run with an external Jython. So you have to stay with the 2.0.4 in the moment.

    And that:

    Changed in sikuli: status: New → In Progress. importance: Undecided → Medium. assignee: nobody → RaiMan (raimund-hocke). milestone: none → 2.0.6

    So I installed version 2.0.4 & Jython 2.7.2 and the problem was solved!