Python Forum

Full Version: Need small help on dynamic database connections
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I am new to python coding .

I am using oracle 11g db in my environment .

I want to connect different users in database and fetch the data from tables.

i trying to create dynamic database connections but i am not able to complete.

Below is my code,please can you correct and help me on dynamic database connection.

import cx_Oracle
shuttles = ['columbia','Brazil']
for c in shuttles:
SQL_columbia='select * from departments order by department_id'
SQL_Brazil='select * from departments order by department_id'
SQL='SQL'+'_'+c
con_columbia=("chr","hr","localhost/xe")
con_Brazil=("bhr","hr","localhost/xe")
dbdetails='con'+'_'+c
mydb=dbdetails
print mydb
con=cx_Oracle.connect(mydb)
print con
cur = con.cursor()
cur.execute(SQL)
for result in cur:
print result
cur.close()
con.close()
Python code doesn't make sense without indentation, so we can't really look at your code if you don't offer your code in a legible format.
https://python-forum.io/misc.php?action=help&hid=25

That said, I don't see anything too crazy in your code. You're connecting to two different databases, and running the same query against each, right?
I will do that .

Based  on country i want call that db connection and SQL.

While executing the above code i am getting cx_Oracle.DatabaseError: ORA-01005: null password given; logon denied error.
You should simplify your code.  Get something that works with just one database first, otherwise you're making it more difficult on yourself to do the easy parts (like logging into the db).
first of all, post your code in code tags and proper indentation. your code is a mess and does not make much sense even without missing indentation (no offense).