我是python新手,我正在尝试如何连接到远程oracledb并使用python脚本运行select查询。以下是我要达到的目标:1) Connect to oracle db and run select query
2) Write the result to the file.
这是我使用的常规连接字符串:
^{pr2}$
不太清楚如何在python3.4中实现,在2.7mysqldb模块/库中使用。在**Here is my blueprint:**
#!/bin/python
import sqlite3
import sys
import os
config = {
'user': 'user',
'password': '*****',
'host': '127.0.0.1',
'database': 'test',
'raise_on_warnings': True,
}
conn = sqlite3.connect('config') # not sure how to pass user and password
c = conn.cursor()
c.execute('select * from employees where employ_id=12')
2)而且我不知道如何在文件中写入它,我的第一个猜测是使用stdin和stdout进行操作,我相信有一种更有效的方法可以做到这一点。在orig_stdout = sys.stdout
out = open("/output.txt", 'w')
sys.stdout = out
c.execute('select * from employees where employ_id=12')
sys.stdout = orig_stdout
out.close()
有人能就更好的解决办法提出建议吗?在