18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

MySQL returning undefined

edited November -1 in Sahi - Open Source
Hello,
I'm new to both Sahi and Java - I was hoping that some one could give me a hand with connecting to my MySQL database.
After reading up on the _getDB command I downloaded the Java connector for MySQL and modified my sahi.bat to include it.
Then I created a script to connect to my database and run a basic query. It seems to run, but when ever I do an alert or assert it reports my vales as 'undefined', I seem to be getting the right number of values - I'm just unable to read them.
If anyone has a suggestion that would be great.


sahi.bat:
SET MOZ_NO_REMOTE=1
java -classpath ..\lib\sahi.jar;.\mysql-connector-java-5.1.5-bin.jar; net.sf.sahi.Proxy

script:
var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.67.1/test", "username", "password");
var $rs = db.select("select FirstName from tblclients");
_alert($rs[0][0]);

Comments

  • narayannarayan Administrators
    var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.67.1/test", "username", "password");
    var $rs = [];
    _set($rs, db.select("select FirstName from tblclients"));
    _alert($rs[0][0]);
  • I have this:

    var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/test", "root", "");
    var $rs = [];
    _set($rs, db.select("select * from item"));
    _alert($rs[0][0]);

    An I get:

    ReferenceError: db is not defined
    Click for browser script [object JavaObject] at 2009-02-02 19:37:48

    In Statements i get:

    setServerVar('\$rs', db.select("select * from item"));
    setServerVar('\$rs', db.select("select * from item"));
    setServerVar('\$rs', db.select("select * from item"));
    setServerVar('\$rs', db.select("select * from item"));
    setServerVar('\$rs', db.select("select * from item"));
    --Stopped Playback: FAILURE--
  • Hi,
    Try this:
    var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/test", "root", "");
    var $rs = new Array();
    $rs[0] = [];
    _set($rs, db.select("select * from item"));
    _alert($rs[0]["COLUMN NAME"]);//Replace with whatever is the table's column name is for example Name, Age etc.

    Regards,
    Pankaj.
  • I still get: ReferenceError: db is not defined
  • narayannarayan Administrators
    Guys, from V2 please use
    var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/test", "root", "");
        var $rs = db.select("select * from item");
        _alert($rs[0]["ColName"]);
    
    _set($rs, db.select("select * from item")); will NOT work with V2.

    Regards,
    Narayan
  • Hi,

    I have encountered an issue when connecting to my MySQL database. I have downloaded mysql-connector-java-5.0.4-bin.jar and copied at ..\extlib\db\ and inclueded in sahi.bat

    I created a script to connect to my database and run a basic query. It seems to run, but when ever I do an alert or assert it reports my vales as 'undefined',

    sahi.bat

    SET EXT_CLASS_PATH=;
    SET EXT_CLASS_PATH=..\lib\sahi.jar;..\extlib\db\mysql-connector-java-5.0.4-bin.jar
    SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
    SET MOZ_NO_REMOTE=1
    java -classpath %EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.Proxy


    Script:

    //Here mysql is my database name
    //mysql is my table name

    var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/mysql", "root", "public");
    var $rs = db.select("select * from mysql");
    _assertEqual("1", $rs[0]["ID"]);

    can you please resolve my issue.
    %0
  • sumeetsumeet Members
    Try below jdbc url and see if it works

    jdbc:mysql://<hostname>:<port>/<dbname>
  • Hi,

    No need to mention port number.

    I have done mistake in mysql table. The issue has resolved.

    Regards
    Asho
Sign In or Register to comment.