← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #218182]: Connectiong to MSSQL using JDBC

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
the class path entry for the driver must be BEFORE any other entries in
the class path and this must be assured to be so at runtime. with the
current Sikuli internal setup, this is not possible. So this is the
reason for the error as explained in comment #6.

To get this working, you cannot run the script any longer in the IDE, it
must be run from command line. Furthermore, Sikuli's script running
feature cannot be used any longer, you must use the Jython interpreter
directly (either the standalone (which you seem to have) or the one
contained in sikuli-script.jar).

Nevertheless, it is possible, to edit and test the script in the IDE, as
long as you make the script to accept that JDBC does not do anything.
One possibility is to hide the JDBC feature in some def()'s, that return
some stuff, that does not crash the script (some test data), just to
assure, your script does what you want.

*** the setup:
# the script: main.sikuli
from sikuli import *
conn = None

def jdbcConnect():
    global conn
    SQLDriver = 'com.microsoft.jdbc.sqlserver.SQLServerDriver'
    d, u, p, v = "jdbc:microsoft:sqlserver://" + ip_address, username, password, SQLDriver
    try:
        conn = zxJDBC.connect(d, u, p, v)
    except:
        pass

def jdbcGet():
     if not conn:
         return "some information"
     else:
         # e.g. get next record
         return record

# start jdbc
jdbcConnect()
# ... some code
rec = jdbcGet()
paste(rec)

Since you hide the JDBC problem, your main workflow will always work.
You do not need to use def()'s for that (though it is THE solution), simple if:/else: constructs do the job as well.

To run the script from commandline now using JDBC:

java -cp path-to-jdbc-driver.jar;path-to-sikuli-script.jar
org.python.util.jython absolute-path-to-main.sikuli\main.py

*** Take care: the images are not found ...
... since the standard setting for the image path is not run in this case

the following helps to set it:
(the script MUST be given with absolute path on command line)

import sys
import os
script = sys.argv[0]
dir = os.path.dirname(script)
print script
print dir

setBundlePath(dir)
find("some-image.png")

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