18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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
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]);
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
var $rs = [];
_set($rs, db.select("select FirstName from tblclients"));
_alert($rs[0][0]);
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--
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.
Regards,
Narayan
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
jdbc:mysql://<hostname>:<port>/<dbname>
No need to mention port number.
I have done mistake in mysql table. The issue has resolved.
Regards
Asho