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.
Not connecting to MySQL Database
Hi,
var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/sampleDB", "root", "");
var $rs = new Array();
$rs[0] = [];
_set($rs, db.select("select * from users"));
_alert($rs[0]["login"]);
after executing the above scripts, it gives me error as db is not defined. I am trying to connect MySql Database.
in Sahi Batch file..
set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar
SET EXT_CLASS_PATH=%SAHI_HOME%\extlib\db\mysql-connector-java.jar
SET MOZ_NO_REMOTE=1
Please help me.
Amol
var db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/sampleDB", "root", "");
var $rs = new Array();
$rs[0] = [];
_set($rs, db.select("select * from users"));
_alert($rs[0]["login"]);
after executing the above scripts, it gives me error as db is not defined. I am trying to connect MySql Database.
in Sahi Batch file..
set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar
SET EXT_CLASS_PATH=%SAHI_HOME%\extlib\db\mysql-connector-java.jar
SET MOZ_NO_REMOTE=1
Please help me.
Amol
Comments
_set($rs, db.select("select * from users"));
to
var $rs = db.select("select * from users");
It is advisable to use $db instead of db.
After setting as per the comment, now it gives me syntax error.
var $db = _getDB("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/kubbe", "root", " ");
var $rs = $db.select("select * from users");
_alert($rs[0]["login"]);
Please help
Amol
SET SAHI_EXT_CLASS_PATH=
as
SET SAHI_EXT_CLASS_PATH=%SAHI_HOME%\extlib\db\mysql-connector-java-5.0.4-bin.jar
Please make sure, the mysql jar file is located in the above mentioned path and try changing the url "jdbc:mysql://localhost/kubbe" as "jdbc:mysql://localhost:3306/kubbe" because the default port number of mysql is 3306.
Go to userdata's bin directory and start sahi from start_sahi.
Thank u once again
Amol
ERROR
exception: java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.sahi.util.ClassLoadHelper.getClass(ClassLoadHelper.java:24)
at net.sf.sahi.plugin.DBClient.getResult(DBClient.java:95)
at net.sf.sahi.plugin.DBClient.select(DBClient.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:247)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3330)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
at net.sf.sahi.rhino.RhinoScriptRunner.run(RhinoScriptRunner.java:114)
at java.lang.Thread.run(Thread.java:619) at 12 Jun, 2013 4:28:13 PM
My Script Is....
_setValue(_textbox("customerId"), "1");
_setValue(_textbox("username"), "a");
_setValue(_password("password"), "a");
_click(_submit("Login"));
$db=_getDB("org.postgresql.Driver","jdbc:postgresql://192.168.1.21:5432/SIDDHERPU1db","maxigems","maxigems");
$rs=$db.select("SELECT * from SALES_QUOTATION_INFO_TABLE");
_prompt($rs);
exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.sf.sahi.util.ClassLoadHelper.getClass(ClassLoadHelper.java:10)
at net.sf.sahi.plugin.DBClient.getConnection(DBClient.java:204)
at net.sf.sahi.plugin.DBClient.getResult(DBClient.java:112)
at net.sf.sahi.plugin.DBClient.select(DBClient.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1479)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3282)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
at org.mozilla.javascript.Context.evaluateString(Context.java:1219)
at net.sf.sahi.rhino.RhinoScriptRunner.executeJS(RhinoScriptRunner.java:254)
at net.sf.sahi.rhino.RhinoScriptRunner.run(RhinoScriptRunner.java:234)
at java.lang.Thread.run(Unknown Source)
(RhinoScriptRunner.run#1277)