Connect to the database using python-set Chinese Characters in oracle and mysql,

Source: Internet
Author: User

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.

 

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.