Python Connection database-set Oracle, MySQL Chinese character issue

Source: Internet
Author: User

1 Importcx_oracle2 ImportMySQLdb3 4 defconn_oracle ():5CNN = Cx_oracle.connect (' User name','Password','IP: Port number/Database') //user name, password, IP port number database6Cur =cnn.cursor ()7     returnCnn,cur8 9 Ten defclose_oracle (cnn,cur): One cur.close () A cnn.close () -  - defconn_mysql (): theCNN = MySQLdb.connect (user="User name", passwd=' Password', host='localhost', db=' Database', charset='UTF8'user name, password, IP, database, character settings -Cur =cnn.cursor () -     returnCnn,cur -  + defClose_mysql (cnn,cur): - cur.close () +Cnn.close ()

NOTE: 1, Oracle sets the character set, assuming that there is a Chinese

Oracle Set character sets Import osos.environ['nls_lang'simplified Chinese_china. UTF8'

2. mysql setting character set charset= "

MySQLdb.connect (user=" username ", passwd=' password ', host=' localhost ', db=' database ', charset='UTF8'

Chinese characters are the most annoying in Python.

Python Connection database-set Oracle, MySQL Chinese character issue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.