본문 바로가기
기술자료/DB

초간단 소스 ODBC Driver Adapter Connect Test python MS-SQL Database

by 와이즈캣 2021. 10. 6.
728x90
반응형

============================================================

import pyodbc

conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=192.168.0.146;PORT=1433;DATABASE=ShopDB;UID=Wowcat;PWD=cocoon115;')
cursor = conn.cursor()

cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
    print(row[0])
    row = cursor.fetchone()


============================================================

 

 

============================================================

import pyodbc

Ip      = '192.168.0.146'
Port    = '1433'
DB      = 'ShopDB'
ID      = 'Wowcat'
PW      = 'cocoon115'

conn = pyodbc.connect(
        'DRIVER=FreeTDS;'
        'SERVER='+Ip+ ';'
        'PORT='+ Port + ';'
        'DATABASE='+ DB + ';'
        'UID='+ ID + ';'
        'PWD='+ PW +';'
        )
cursor = conn.cursor()
querySelect = "SELECT * FROM memberTBL;"
#queryInsert = "INSERT INTO memberTBL VALUES('Han1','한가람','부산시 금정구');"
#cursor.execute(queryInsert)
#conn.commit()

cursor.execute(querySelect)
row = cursor.fetchone()
while row:
    print(row)
    row = cursor.fetchone()


============================================================

728x90