Four, Python connect Oracle Database---windows7 operating system

Source: Internet
Author: User

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

Related Article

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.