Issue when accessing to MySQL database

Asked by rod

Hi all,

I'm using the last version of sikuli on Windows 7 with jre7.
I downloaded the last java mysql connector (5.1.28) and added a env variable :
CLASSPATH = C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar

I'm so launching a sikuli script (no IDE) with basically :

from sikuli import *
from com.ziclix.python.sql import zxJDBC

j = 'jdbc:mysql://localhost:3306/BinckAutoTest'
u = 'root'
p = 'mypassword'
m = 'com.mysql.jdbc.Driver'

try:
  con = zxJDBC.connect(j, u, p, m)
except Exception, e:
  print "database connection issue : ", e

And I'm getting :
database connection issue : driver [com.mysql.jdbc.Driver] not found

Looking at another post (question 202408) I saw that RaiMan proposed a bat script like :

set cp=C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar
set cp=%cp%:C:\tmp\jython.jar
java -cp %cp% org.python.util.jython %1.sikuli\%1.py

When I run this bat script I get :
Error: Could not find or load main class Files

Where Am I wrong ?

Thanks a lot,
Rod

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
rod
Solved:
Last query:
Last reply:

This question was reopened

  • by rod
Revision history for this message
obiwan-92 (obiwan-92) said :
#1

Hello,

I'm not sure but try with semicolon :
replace set cp=%cp%:C:\tmp\jython.jar
by set cp=%cp%;C:\tmp\jython.jar

Tell me if it's work.

Revision history for this message
rod (rodhiguain) said :
#2

no, it still doesn't work :

set cp=C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar
set cp=%cp%;C:\tmp\jython.jar
java -cp %cp% org.python.util.jython %1.sikuli\%1.py

Error: Could not find or load main class Files

Revision history for this message
RaiMan (raimund-hocke) said :
#3

add
-Dsikuli.Debug=3

to the java command line

To find out, at what state it crashes.

Revision history for this message
rod (rodhiguain) said :
#4

This error ("Could not find or load main class Files") doesn't rise when I run the sikuli script but when I execute the bat script.

I'm using this bat in order to fix the problem (see Question #202408) of sikuli to connect to the database because of :
driver [com.mysql.jdbc.Driver] not found

Thanks again

Revision history for this message
RaiMan (raimund-hocke) said :
#5

I know, but in the bat, the only command doing something is the java command, that is advised, to load the class org.python.util.jython from class path, which is the Jython interpreter, that should be in your C:\tmp\jython.jar (assuming this is the correct one).

since you have a ref to a .py file on the java command, the Jython interpreter will try to run it and hence the first thing he will do:
from sikuli import *

... writing this, I just realised, that you do not have a ref to a Sikuli jar in your class path and since %cp% in the end contains blanks:

java -cp "%cp%;--ref-to-sikuli-jar--" org.python.util.jython %1.sikuli\%1.py

where --ref-to-sikuli-jar-- must be for
RC3: the absolute path to sikuli-script.jar
version 1.0.1: the absolute path to sikuli-java.jar

Revision history for this message
RaiMan (raimund-hocke) said :
#6

another option is to use the following line in another bat:

java -cp "%cp%;--ref-to-sikuli-jar--" org.python.util.jython

this will start an interactive Jython session, where you could enter Jython stuff line by line and might find out this way, what's wrong

and for the script I would recommend this sequence:

from com.ziclix.python.sql import zxJDBC

j = 'jdbc:mysql://localhost:3306/BinckAutoTest'
u = 'root'
p = 'mypassword'
m = 'com.mysql.jdbc.Driver'

try:
  con = zxJDBC.connect(j, u, p, m)
except Exception, e:
  print "database connection issue : ", e
  exit()
from sikuli import *

So Sikuli stuff is only touched, if the connection is successful.

Revision history for this message
rod (rodhiguain) said :
#7

OK, now it's more clear to me.

1) I downloaded the java mysql connector and added an env variable :
CLASSPATH = C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin

2) I downloaded a standalone jython-standalone-2.5.3.jar in "C:\Jython" and :

set cp=C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar
set cp=%cp%;C:\Jython\jython-standalone-2.5.3.jar

3) I opened a Jython session with :
java -cp "%cp%;C:\apps\SikuliX" org.python.util.jython

>>> con = zxJDBC.connect(j, u, p, m)

and I could connect to my Mysql database and make same select without problems !!

4) Then I tried to import sikuli :

>>> from sikuli import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sikuli

Revision history for this message
rod (rodhiguain) said :
#8

Why sikuli module is not found ?

Revision history for this message
RaiMan (raimund-hocke) said :
#9

On the class path you need
java -cp "%cp%;C:\apps\SikuliX\sikuli-java.jar" org.python.util.jython

and you need the jar internal Lib folder to be on Jython sys.path:
so to activate Sikuli with version 1.0.1 in this situation:
import org.sikuli.basics.SikuliXforJython
from sikuli import *

(as mentioned here: https://github.com/RaiMan/SikuliX-API/wiki/Usage-in-Java-programming)

Revision history for this message
rod (rodhiguain) said :
#10

Still a fatal error...

Here my steps :

1) set CLASSPATH=C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar
2) set CLASSPATH=%CLASSPATH%;C:\Jython\jython-standalone-2.5.3.jar
3) java -cp "%CLASSPATH%;C:\apps\SikuliX\sikuli-ide.jar" org.python.util.jython

>>> from com.ziclix.python.sql import zxJDBC
>>> import org.sikuli.basics.SikuliXforJython
>>> import sys
>>> print sys.path
['', 'C:\\Jython\\Lib', 'C:\\Jython\\jython-standalone-2.5.3.jar\\Lib', '__classpath__', '__pyclasspath__/', u'/C:/apps/SikuliX/sikuli-ide.jar/Lib']
>>> from sikuli import *
[error] ResourceLoaderBasic: loadLib: Fatal Error 110: loading: WinUtil.dll
[error] ResourceLoaderBasic: loadLib: Since native library was found, it might be a problem with needed dependent libraries
C:\apps\SikuliX\libs\WinUtil.dll: Can't find dependent libraries
[error] ResourceLoaderBasic: loadLib: Check, wether a valid Sikuli libs folder is in system path at runtime!
[error] Terminating SikuliX after a fatal error(110)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.

Revision history for this message
RaiMan (raimund-hocke) said :
#11

why not doing, what I suggested in comment #9?
sikuli-ide.jar should not be used with external Jython, since it itself contains a Jython built-in, that might conflict.

as the error said: Check, wether a valid Sikuli libs folder is in system path at runtime!

Revision history for this message
rod (rodhiguain) said :
#13

Sorry Raiman,
but I do not have any sikuli-java.jar in my C:\apps\SikuliX.

In my Sikuli packages there are only 3 jar files :
- sikuli-ide.jar
- sikuli-setup.jar
- sikuli-tessdata.jar

How can I get this sikuli-java.jar ?

Revision history for this message
RaiMan (raimund-hocke) said :
#14

delete everything in the setup folder except sikuli-setup.jar and repeat the setup with options 1, 3, 5

Revision history for this message
rod (rodhiguain) said :
#15

I cleaned the setup folder and installed packages 1,3 and 5 (and got the sikuli-java.jar file !).

1) echo %CLASSPATH%
C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.28-bin.jar;C:\Jython\jython-standalone-2.5.3.jar

2) java -cp "%CLASSPATH%;C:\apps\SikuliX\sikuli-java.jar" org.python.util.jython

>>> print sys.path
['', 'C:\\Jython\\Lib', 'C:\\Jython\\jython-standalone-2.5.3.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\apps\\SikuliX', 'C:\\apps\\SikuliX\\sikuli-java.jar']
>>> from com.ziclix.python.sql import zxJDBC
>>> import org.sikuli.basics.SikuliXforJython
>>> from sikuli import *
[error] ResourceLoaderBasic: loadLib: Fatal Error 110: loading: WinUtil.dll
[error] ResourceLoaderBasic: loadLib: Since native library was found, it might be a problem with needed dependent libraries
C:\apps\SikuliX\libs\WinUtil.dll: Can't find dependent libraries
[error] ResourceLoaderBasic: loadLib: Check, wether a valid Sikuli libs folder is in system path at runtime!
[error] Terminating SikuliX after a fatal error(110)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.

Revision history for this message
RaiMan (raimund-hocke) said :
#16

You should at least log out and log in again after having setup SikuliX on Windows.

If the problem persists, do this

2) java -Dsikuli.Debug=3 -cp "%CLASSPATH%;C:\apps\SikuliX\sikuli-java.jar" org.python.util.jython

you might post the debug output here or send it silently to my mail at https://launchpad.net/~raimund-hocke

Revision history for this message
rod (rodhiguain) said :
#17

Thanks a lot Raiman I sent you an email with all details.

Revision history for this message
rod (rodhiguain) said :
#18

Here how to solve this problem : https://answers.launchpad.net/sikuli/+question/242975

Thanks a lot Raiman !