问题
I have to connect oracle database to extract data and write into pandas data frame.
All I have available with me is Hostname , Port, Service Name
import cx_Oracle
Hostname = 'XX.XX.X.XXX'
port = 1521
Service_Name = 'DPP2.kn.com'
dsn_tns = cx_Oracle.makedsn(Hostname, port, Service_Name)
connection = cx_Oracle.connect('BA', 'PASSWORD', dsn_tns)
Its not working.How to fix this
回答1:
You can use cx_Oracle.connect
method as
dsn_tns = cx_Oracle.connect(username+"/"+password+"@"+ Hostname+":"+port+"/"+Service_Name)
cursor = dsn_tns.cursor()
and then retrieve data through cursor.execute()
来源:https://stackoverflow.com/questions/55432712/how-connect-to-database-to-extract-data-and-write-pandas-dataframe