The connection application of the database is an important knowledge point of each programming language, this article records how to connect the database under Python.
The local environment is as follows:
System: Windows7 64 bits
Python version: python2.7
Database: Oracle 11g
Operation Steps:
1, download embedded in Python database module, because I am python2.7 so download Cx_oracle-5.1.2-11g.win32-py2.7.msi (64-bit system is completely compatible with this version, do not worry), the installation process is as follows:
1 after downloading, click Install directly, appear the following diagram interface:
2 Click "Next" and appear as follows: (Automatically select the Python I have installed)
3 Click "Next" to complete the installation, and the "Cx_oracle-5.1.2-py2.7.egg-info" folder appears in the folder where you install Python (C:\Python27\Lib\site-packages), as shown below:
2, after the completion of the module installation, can be tested in the Python program, the following figure:
Code:
#-*-Coding:utf-8-*-
import cx_oracle
conn=cx_oracle.connect (' username ', ' pwd ', ' LOCALHOST:1521/ORCL ')
cursor=conn.cursor ()
sql= "SELECT * from Sys_user"
cursor.execute (SQL)
Data=cursor.fetchall ()
print (data)
cursor.close ()
conn.commit ()
conn.close ()
As shown in the figure above, the database connection is successful.
More about the database can be referred to: http://www.runoob.com/python/python-mysql.html