Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## libraries
- import pyodbc
- import numpy as np
- import pandas as pd
- ## initial setting
- ## 適宜設定値は変えて下さい
- server = 'abc_server.database.windows.net'
- database = 'abc_database'
- username = 'abc_user'
- password = 'abc_password'
- ## 関数定義
- ### DB connectionを定義
- def db_connection(sv=server, db=database, un=username, pw=password):
- cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+sv+';DATABASE='+db+';UID='+un+';PWD='+ pw)
- return cnxn.cursor()
- ### SQLを発行
- def query_output(sql):
- cursor.execute(sql)
- row = cursor.fetchone()
- while row:
- print row[0]
- row = cursor.fetchone()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement