DBILITY

pymssql을 사용한 SQL Server 접속 테스트 본문

python

pymssql을 사용한 SQL Server 접속 테스트

DBILITY 2025. 9. 24. 10:57
반응형

driver가 필요하니 pymssql install

pip install pymssql

db_test.py

import pymssql

server = "localhost"
user = "사용자"
password = "비밀번호"
database = "대상 데이터베이스명"

try:
    conn = pymssql.connect(server=server, user=user, password=password, database=database)
    cursor = conn.cursor()
    sql = """
    	SELECT A, B, C, D FROM DUMMY_TABLE
    """
    cursor.execute(sql)
    rows = cursor.fetchall()
    for row in rows:
        print(row)

    cursor.close()
    conn.close()

except Exception as e:
    print(f"Error Connecting To SQL Server: {e}")

fetch된 row의 type을 확인해 보니 Tuple이다. 당연한 것인가?. 불변이어야 하니.

반응형

'python' 카테고리의 다른 글

pip를 통한 package install 등..  (0) 2025.09.23
python matplot scatter chart , linear regression line exercise  (0) 2021.10.13
python pandas dataframe  (0) 2021.10.12
python papago translate api example  (0) 2021.10.12
python matplot pie chart  (0) 2021.08.30
Comments