Python Forum
Need small help on dynamic database connections
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need small help on dynamic database connections
#1
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()
Reply
#2
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?
Reply
#3
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.
Reply
#4
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).
Reply
#5
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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Small Database Program (Need Help) thewetmosquito 3 2,199 Jul-11-2020, 01:51 PM
Last Post: menator01
  How can I make this server stop listening for connections to sockets Emekadavid 0 3,447 Jun-03-2020, 02:28 PM
Last Post: Emekadavid
  Creation of Dynamic HTML by substituting Database values Sandy777 1 2,136 Apr-18-2019, 07:17 AM
Last Post: buran
  SSH connections Will 3 3,711 Jun-19-2017, 12:19 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020