Connect to the database using python-set Chinese Characters in oracle and mysql,
1 import cx_Oracle 2 import MySQLdb 3 4 def conn_oracle (): 5 cnn = cx_Oracle.connect ('username ', 'Password', 'IP: Port Number/database') // user name, password, ip port number database 6 cur = cnn. cursor () 7 return cnn, cur 8 9 10 def close_oracle (cnn, cur): 11 cur. close () 12 cnn. close () 13 14 def conn_mysql (): 15 cnn = MySQLdb. connect (user = "user Name", passwd = 'Password', host = 'localhost', db = 'database', charset = 'utf8') user name, password, ip address, database, character Set 16 cur = cnn. cursor () 17 return cnn, cur18 19 def close_mysql (cnn, cur): 20 cur. close () 21 cnn. close ()
Note: 1. Set the character set in oracle. Assume that the character set contains Chinese characters.
Oracle sets the character set import osos. environ ['nls _ LANG '] = 'simplified chinese_china.utf8'
2. mysql sets charset =''
MySQLdb. connect (user = "user Name", passwd = 'Password', host = 'localhost', db = 'database', charset = 'utf8 ')
Chinese characters are the most annoying in python.