Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

Unable to connect to db without using Sahi API

vinothtvinotht Members
edited November 2013 in Sahi Pro
I am using Sahi 4.5.1
ojdbc6.jar is placed to sahiHome\extlib\db folder
"set SAHI_EXT_CLASS_PATH=%SAHI_HOME%;C:\sahi_pro\extlib\db\ojdbc6.jar;" is added to SahiHome\bin\dashboard.bat at :startsahi

And FYI _getDB is working fine with the above settings but the following function which directly fetches the db data without using Sahi API is failed. Please have a look

function Execute_Query($Sql)
{
try
{
java.lang.Class.forName("oracle.jdbc.driver.OracleDriver");
var $DB = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@OraDBServer01:1521:OraDB" , "User01","Sahi678");
_alert($DB) \\ alerts undefined;
$Stmt = $DB.createStatement();
$RS = $Stmt.executeQuery($Sql);
return ($RS);
}
catch ($e)
{
_debug($e);
}
finally
{
}
}
//function call:
var $Records = Execute_Query("select * from users");
//$Records retrieved is null

Should i have to do any changes in sahi config files

Answers

  • used external java class file to connect db.

    Steps:
    1. Create a java class file and export it as a jar file
    2. place the jar file in sahi_userdata_dir\extlib folder (create extlib folder if not exists)
    3. set the jar file path in Start_Dashboard.bat for "SAHI_EXT_CLASS_PATH" variable as shown below
    SET SAHI_EXT_CLASS_PATH=%SAHI_USERDATA_DIR%\extlib\testdb.jar;
    4. Restart sahi and call the java methods to execute db queries

    Thanks,
    Vinoth
Sign In or Register to comment.