RobotFramework Oracle DB Connection Issue - jdbc

I'm trying to check if the oracle DB connection using the Keyword:
Connect To Database Using Custom Params
Following libraries are imported:
Database Library
JayDeBe API
This this is the connection string used:
'oracle.jdbc.driver.OracleDriver', 'jdbc:oracle:thin:#//DBHostname:Port/DBName', ['user', 'pass']
We do not get any response that can identify if the connection is established or rejected.
We see this message in RIDE:
'oracle.jdbc.driver.OracleDriver', 'jdbc:oracle:thin:#//DBHostName:Port/DBName', ['user', 'pass']
20170927 17:07:54.438 : INFO : Executing : Connect To Database Using Custom Params : jaydebeapi.connect(db_api_2.connect('oracle.jdbc.driver.OracleDriver', 'jdbc:oracle:thin:#//DBHostName:Port/DBName', ['user', 'pass']))
Can someone please help us?

We found the solution: In our case we have python 2.7(32bit) therefore we need the following:
1. Oracle Instant Client Downloads for Microsoft Windows (32-bit). you can download it from here: http://www.oracle.com/technetwork/topics/winsoft-085727.html
Set the variable path in environment variable for the Oracle Instant client.
Download cx_Oracle API (32bit- cx_Oracle-6.0.2-cp27-cp27m-win32.whl (md5) ) from the location:https://pypi.python.org/pypi/cx_Oracle/
Open command prompt and run: pip install cx_Orcle --upgrade
Open the RIDE and use the following keyword:
Connect To Database Using Custom Params cx_Oracle 'user', 'password', 'DBHOSTNAME:PORT/DBNAME'

Related

How to install JDBC driver on Databricks Cluster?

I'm trying to get the data from my Oracle Database to a Databricks Cluster. But I think I'm doing it wrong:
On the cluster library I just installed the ojdbc8.jar and then after that I opened a notebook and did this to connect:
CREATE TABLE oracle_table
USING org.apache.spark.sql.jdbc
OPTIONS (
dbtable 'table_name',
driver 'oracle.jdbc.driver.OracleDriver',
user 'username',
password 'pasword',
url 'jdbc:oracle:thin://#<hostname>:1521/<db>')
And it says:
java.sql.SQLException: Invalid Oracle URL specified
Can someone help? I've been reading documentations but there's no clear instruction on how I should actually install this jar step by step. I might be using the wrong jar? Thanks!
I have managed to set this up in Python/PySpark as follows:
jdbcUrl = "jdbc:oracle:thin:#//hostName:port/databaseName"
connectionProperties = {
"user" : username,
"password" : password,
"driver" : "oracle.jdbc.driver.OracleDriver"
}
query = "(select * from mySchema.myTable )"
df = spark.read.jdbc(url=jdbcUrl, table=query1, properties=connectionProperties)
I am using the Oracle JDBC Thin Driver instantclient-basic-linux.x64-21.5.0.0.0, as available on the Oracle webpages. The current version is 21.7 I think, but it should work the same way.
Check this link to understand the two different notations for jdbc URLs

cx_Oracle connection by python3.5

I've tried several attempt to connect Oracle DB but still unable to connect. Following is my code to connect. However, I could connect Oracle DB through the terminal like this:
$ sqlplus64 uid/passwd#192.168.0.5:1521/WSVC
My evironment: Ubuntu 16.04 / 64bit / Python3.5
I wish your knowledge and experience associated with this issue to be shared. Thank you.
import os
os.chdir("/usr/lib/oracle/12.2/client64/lib")
import cx_Oracle
# 1st attempt
ip = '192.168.0.5'
port = 1521
SID = 'WSVC'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
# dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)
db = cx_Oracle.connect('uid', 'passwd', dsn_tns)
cursor = db.cursor()
-------------------------------------------------
# 2nd attempt
conn = "uid/passwd#(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.5)(PORT=1521)))(CONNECT_DATA=(SID=WSVC)(SRVR=DEDICATED)))"
db = cx_Oracle.connect(conn)
cursor = db.cursor()
------------------------------------------------------
# ERROR Description
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
The error "unable to acquire Oracle environment handle" is due to your Oracle configuration being incorrect. A few things that should help you uncover the source of the problem:
when using Instant Client, do NOT set the environment variable ORACLE_HOME; that should only be set when using a full Oracle Client or Oracle Database installation
the value of LD_LIBRARY_PATH should contain the path which contains libclntsh.so; the value you selected looks like it is incorrect and should be /usr/lib/oracle/12.2/client64/lib instead
you can verify which Oracle Client libraries are being loaded by using the ldd command as in ldd cx_Oracle.cpython-35m-x86_64-linux-gnu.so

PDO cannot find ODBC driver

Trying to migrate to PDO for an ODBC connection to a remote database.
My system is Windows 7 Pro, with a FortiClient VPN connection to the remote domain, and Tunnel Mode connected. (Added in edit: Running PHP 5.4, so PDO should be installed by default.)
The data source configuration in the Windows 7 ODBC Data Source Administrator is as follows (some names changed for security):
Under System DSN:
System Data Source Name = 'TheBigDB'
Driver = 'Oracle in instantclient_11_2' (64-bit)
TNS Service Name = '10.10.1.20:1521/BIGDB'
UserID = 'BigDBUser'
All other settings are defaults for installation of driver
The following piece of PHP non-PDO code is able to create a connection usable for queries:
if (!($myConn = odbc_connect('TheBigDB','BigDBUser','myPwd'))) {
echo "No ODBC connection<br />";
}
So I can connect to the database. The problem is doing it in PDO. The following PHP...
try {
$odbcConn = new PDO('odbc:Driver={Oracle in instantclient_11_2};Server=10.10.1.20:1521;Database=BIGDB;Uid=BigDBUser;Pwd=myPwd');
} catch (PDOException $e) {
echo 'PDO connection failed: ' . $e->getMessage();
}
... results in a PDO connection failed: could not find driver message. My first try relied more heavily on the Data Sources Administrator; that looked like this:
try {
$odbcConn = new PDO('MyBigDB','BigDBUser','myPwd');
} catch (PDOException $e) {
echo 'PDO connection failed: ' . $e->getMessage();
}
Same thing -- could not find driver.
So here's my question: Given a Windows 7 system with ODBC through a VPN connection to an Oracle database that all seems to work without PDO, how do I migrate the connection parameters to create a PDO connection? Maybe a better question is why mess with PDO for the connection, but I keep reading that PDO is more secure, so I'm trying to use it.
More digging got me an answer. The correct syntax for creating a PDO object that uses a Windows Data Sources ODCB connection is not what I showed, but instead this (minus the try/catch):
$myConn = new PDO('odbc:TheBigDB','BigDBUser','myPwd');
BUT... with PHP 5.4.12 using ODBC to touch an Oracle 11 DB, you need to edit the correct php.ini file (see this WampServer forum topic for a discussion of which of three php.ini files you need to edit). Under Dynamic Extensions, uncomment extension=php_pdo_odbc.dll and extension=php_pdo_oci.dll (I did both; not sure which one did the trick...)
Another tip: In my scripts, neither odbc_connect() nor PDO() worked for me unless my connection was created in Windows Data Sources Administrator under the System DSN tab. It did not work under User DSN.

RobotFramework : cx_Oracle - FAIL : InternalError: No Oracle error?

Couldn't find a solution for my problem using search so I created this topic.
I'm having problems when connecting to Oracle database using DataBase libary and cx_Oracle module.
In python import cx_Oracle works great (returns no error), but when I try to connect to DB on RobotFramework with Connect To Database Using Custom Params | cx_Oracle | 'user', 'pass', 'host/db'
I get an error : FAIL : InternalError: No Oracle error?
If I try to connect to database using
Connect To Database | dbapiModuleName=cx_Oracle | dbName=db_name | dbUsername=user | dbPassword=pass | dbHost=host | dbPort=port
I get an error : FAIL : TypeError: 'database' is an invalid keyword argument for this function
I'm using Windows7 x86, non-Administrator user, Oracle 11g, Python 2.7.3, cx_Oracle 5.1.2, RobotFramework 2.7.6, RIDE 1.0.1. Everything else works like a charm (connection to database using PLSQLDeveloper, RobotFramework, Selenium2Libary etc.)
Have anyone any ideas how can I solve my problem?
Sincerely,
Kristiāns
I run into the same problem: 'FAIL : TypeError: 'database' is an invalid keyword argument for this function'
This is what works for me:
DatabaseLibrary.Connect To Database Using Custom Params | cx_Oracle | 'user', 'password', 'host:port/dbname'

Connecting to Oracle DB using Ruby

I am stuck with connecting to Oracle DB, have read lots of stuff but no help on result.
I have remote Oracle DB, I am connecting to it using DBVisualizer setting connection like this:
DB Type : Oracle
Driver (jdbc) : Oracle thin
Database URL: jdbc:oracle:thin:#10.10.100.10:1521/VVV.LOCALDOMAIN
UserIdf: SomeUser
Pass: SomePass
Connection works ok.
What I do in Ruby is :
require 'oci8'
require 'dbi'
...
conn = OCI8.new('SomeUser','SomePass','//10.10.100.10:1521/VVV.LOCALDOMAIN')
...
What I get is:
ORA-12545: Connect failed because target host or object does not exist
oci8.c:360:in oci8lib.so
the third parameter needs to be the TNS hostname, if you use SQL plus it is also the third parameter in the connectstring, you can find it also in the tnsnames.ora file in the oracle maps
in SQLPlus : connect user/password#hostname;
in oci8 : conn = OCI8.new('SomeUser','SomePass',hostname)
Here a working sample, obfuscated the parameters of course
require 'oci8'
oci = OCI8.new('****','***','****.***')
oci.exec('select * from table') do |record|
puts record.join(',')
end

Resources