簡體   English   中英

如何修復我的錯誤代碼程序? 我使用Python 3.6

[英]How to fix this my error code program? I use Python 3.6

如何解決此錯誤我使用Python 3.6和Database Oracle,我想從數據庫中打印數據,但是顯示錯誤,我該如何解決?

這是我的數據庫: 在此處輸入圖像描述

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]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM