- 论坛徽章:
- 0
|
- #!/usr/bin/env python
- # -*-coding:UTF-8-*-
- import sys
- import cx_Oracle
- ora_ip="10.0.20.47"
- ora_port="1521"
- SERVICE_NAME="YUYIZHI"
- ora_dsn=cx_Oracle.makedsn(ora_ip,ora_port,SERVICE_NAME)
- print "the dsn is ",ora_dsn
- connection = cx_Oracle.Connection(u"user",u"passwd",ora_dsn)
- cursor = connection.cursor()
- try:
- cursor.execute("select 1 / 0 from dual")
- except cx_Oracle.DatabaseError, exc:
- error, = exc.args
- print >> sys.stderr, "Oracle-Error-Code:", error.code
- print >> sys.stderr, "Oracle-Error-Message:", error.message
- the dsn is (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.20.47)(PORT=1521)))(CONNECT_DATA=(SID=YUYIZHI)))
- Traceback (most recent call last):
- File "1.py", line 17, in ?
- cursor.execute("select 1 / 0 from dual")
- TypeError: expecting None or a string
复制代码 |
|