Thursday, February 15, 2007

Windows XP Professional, IIS Server에서 Python, DB2 연동

DB2 Express-C V9 : DB2 Universal Database Express Edition (DB2 Express) for the community - IDB DB2의 무료버전!!!
Partition 기능사용하려면 license사야함

ActivePython V2.4 : AIX, HP-UX, Linux, Mac OS X, Solaris, Windows에 모두 사용가능한 ActiveState의 Python - 무료
IIS V5.1 : Microsoft Internet Information Server


odbc 이용
---------------
print "Content-type:text/plain\n\n" # 안넣어주면 server에서 결과 볼 때 CGI error

import dbi
import odbc
db = odbc.odbc('DB명/UserID/Password')
cursor = db.cursor()
cursor.execute("set schema='해당DB의Schema명'")
cursor.execute( 'select * from table명' )
result = cursor.fetchall()
print (result)
cursor.close()
db.close()


mx.ODBC이용
---------------
1. ActivePython2.4 설치 (http://activestate.com/Products/ActivePython/)
2. DB2 Express-C 설치 (http://www-306.ibm.com/software/data/db2/udb/db2express/) 무료긴 하지만 IBM에 회원가입을 해야 다운받을 수 있다.
3. ODBC 연결 설정
4. mxODBC 연결 (http://www.egenix.com/files/python/eGenix-mx-Extensions.html#Packages 에서 )

import mx.ODBC
import mx.ODBC.Windows
db = mx.ODBC.Windows.DriverConnect('DSN=xxx;Uid=xxx;Pwd=xxx')
cursor = db.cursor()
cursor.execute("set schema='해당DB의Schema명'")
cursor.execute('select * from table명')
mx.ODBC.print_resultset(cursor)
db.close()

0 Comments:

Post a Comment

<< Home