如何修复这个我的错误代码程序?我用 Python 3.6
How to fix this my error code program? I use Python 3.6
如何解决这个错误 我使用 Python 3.6 和数据库 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
最好使用字符串格式而不是串联,因为您不能添加带有数字的字符串。更改以下行
print('\nNIK : '+row[0])
至
print('\nNIK : {}'.format(row[0]))
如何解决这个错误 我使用 Python 3.6 和数据库 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
最好使用字符串格式而不是串联,因为您不能添加带有数字的字符串。更改以下行
print('\nNIK : '+row[0])
至
print('\nNIK : {}'.format(row[0]))