【发布时间】:2019-07-31 12:31:26
【问题描述】:
如何解决此错误我使用 Python 3.6 和 Database Oracle,我想从数据库中打印数据,但显示错误,我该如何解决?
这是我的数据库: enter image description here
EMPLOYEESID(主键),NIK(唯一键)
这是我的代码:
#import oracle module
import cx_Oracle
#membuat koneksi ke database oracle dan sesuaikan settingannya
con= cx_Oracle.connect("db_employees/root@localhost:1521/xe")
#inisialisasi cursor object methodnya
cur= con.cursor()
#eksekusi query
cur.execute('select*from employees')
#mengambil data dari query
rows = cur.fetchall()
#print data
for row in rows:
print('\nNIK : '+row[0])
print('Nama Karyawan : '+row[1])
print('Jabatan : '+row[3])
print('Birthdate : '+row[4])
print('Address : '+row[5]+ '\n')
#close cursor object
cur.close()
#close connection
con.close()
这是我的消息错误:
C:\Python36>python "D:\bisa.py"
Traceback (most recent call last):
File "D:\bisa.py", line 18, in <module>
print('\nNIK : '+row[0])
TypeError: must be str, not int
【问题讨论】:
-
我看到的第一件事是,您似乎使用“cur”对象而不是实例化对象来存储它。 Ulfa,尝试删除 rows = 并告诉我这给了你什么
-
在尝试打印行的内容之前,先尝试打印“行”,看看它会给你什么。
标签: python oracle oracle11g python-3.6