-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectToCPODB.py
More file actions
94 lines (72 loc) · 2.13 KB
/
Copy pathConnectToCPODB.py
File metadata and controls
94 lines (72 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'''
Created on Feb 17, 2016
@author: sumkuma2
'''
import cx_Oracle
username ='ctmreadonly'
password ='ctm123!'
host = 'eon-rtp5-1-l.cisco.com'
port ='1521'
SID = 'OPTDB'
#con_uri = '{}/{}@{}'.format(username,password,con_identifier)
#connStr='rcuser/D3v4CSPadmin@173.38.50.157:1530/OPSDEV.cisco.com'
#print (con_uri)
myuserlist=[]
try:
'''using connection str '''
#con = cx_Oracle.connect(connStr)
''' using make dsn '''
#dsn_tns = cx_Oracle.makedsn('173.38.50.157', '1530','OPSDEV' )
dsn_tns = cx_Oracle.makedsn(host,port,SID)
con = cx_Oracle.connect(username, password,dsn_tns)
print ("Connection successful to :eon-rtp5-1-l : DB version: ",con.version)
cur = con.cursor()
sql ='''
SELECT
ut.username
FROM
user_table ut,user_type_table utt
WHERE
ut.subtypeofuser = utt.usertypeid and
ut.subtypeofuser = 1
'''
#execute sql query
cur.execute(sql)
#fetch one record
#row = cur.fetchone()
#print "(USERNAME,USERTYPE)"
#print (row)
'''for result in cur:
print (result)
else:
print ("No result found")
'''
#data = cur.fetchone()
rows = cur.fetchall()
#print ("data: "),data
for row in rows:
username = row[0]
myuserlist.append(username)
cur.close()
con.close()
'''con = cx_Oracle.connect('ctmreadonly/ctm123!@173.38.48.103/OPTDB')
cur = con.cursor()
cur.execute('select * from user_table order by userid')
for result in cur:
print (result)
cur.close()
con.close()'''
except cx_Oracle.DatabaseError as e:
error, = e.args
if error.code == 955:
print('Table already exists')
elif error.code == 1031:
print("Insufficient privileges")
print(error.code)
print(error.message)
print(error.context)
#con.close()
#print('Database connection error: %s'.format(e))
print ('Database connection error: %s')%(e)
raise
print myuserlist