# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
print time.ctime()
conn = cx_Oracle.connect('test/test@10.10.17.200/serv')
print '--------conn-------------'
print conn
print type(conn)
print '--------conn-------------'
cursor = conn.cursor()
print '--------cursor------------'
print cursor
print type(cursor)
print '--------cursor------------'
def get_sql():
xsql="select 'aaa' from dual"
cursor.execute(xsql)
result = cursor.fetchall()
print result
while True:
print '--------conn-------------'
print conn
print type(conn)
print '--------conn-------------'
cursor = conn.cursor()
print '--------cursor------------'
print cursor
print type(cursor)
print '--------cursor------------'
get_sql()
time.sleep(2)
--------conn-------------
<cx_Oracle.Connection to test@10.10.17.200/serv>
<type 'cx_Oracle.Connection'>
--------conn-------------
--------cursor------------
<cx_Oracle.Cursor on <cx_Oracle.Connection to test@10.10.17.200/serv>>
<type 'cx_Oracle.Cursor'>
--------cursor------------
[('aaa',)]
--------conn-------------
<cx_Oracle.Connection to test@10.10.17.200/serv>
<type 'cx_Oracle.Connection'>
--------conn-------------
--------cursor------------
<cx_Oracle.Cursor on <cx_Oracle.Connection to test@10.10.17.200/serv>>
<type 'cx_Oracle.Cursor'>
--------cursor------------
[('aaa',)]
关闭数据库:
<type 'cx_Oracle.Cursor'>
--------cursor------------
Traceback (most recent call last):
File "C:/Users/tlcb/PycharmProjects/untitled/rizhiyi/a7.py", line 37, in <module>
get_sql()
File "C:/Users/tlcb/PycharmProjects/untitled/rizhiyi/a7.py", line 24, in get_sql
cursor.execute(xsql)
cx_Oracle.OperationalError: ORA-03113: 通信通道的文件结尾
进程 ID: 2909
会话 ID: 575 序列号: 149
Process finished with exit code 1
关闭数据库直接报错
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
print time.ctime()
conn = cx_Oracle.connect('test/test@10.10.17.200/serv')
print '--------conn-------------'
print conn
print type(conn)
print '--------conn-------------'
cursor = conn.cursor()
print '--------cursor------------'
print cursor
print type(cursor)
print '--------cursor------------'
def get_sql():
xsql="select 'aaa' from dual"
cursor.execute(xsql)
result = cursor.fetchall()
print result
while True:
get_sql()
time.sleep(2)
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import cx_Oracle
from pprint import pprint
import csv
import time
import re
import binascii
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
print time.ctime()
conn = cx_Oracle.connect('test/test@10.10.17.200/serv')
print '--------conn-------------'
print conn
print type(conn)
print '--------conn-------------'
cursor = conn.cursor()
print '--------cursor------------'
print cursor
print type(cursor)
print '--------cursor------------'
def get_sql():
xsql="select 'aaa' from dual"
cursor.execute(xsql)
result = cursor.fetchall()
print result
while True:
try:
get_sql()
time.sleep(2)
except Exception,e:
print e
ORA-03114: 未连接到 ORACLE
ORA-03114: 未连接到 ORACLE
ORA-03114: 未连接到 ORACLE
ORA-03114: 未连接到 ORACLE
ORA-03114: 未连接到 ORACLE
ORA-03114: 未连接到 ORACLE