How connect to database to extract data and write pandas dataframe

こ雲淡風輕ζ 提交于 2019-12-11 15:52:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!