Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. ## libraries
  2. import pyodbc
  3. import numpy as np
  4. import pandas as pd
  5.  
  6. ## initial setting
  7. ## 適宜設定値は変えて下さい
  8. server = 'abc_server.database.windows.net'
  9. database = 'abc_database'
  10. username = 'abc_user'
  11. password = 'abc_password'
  12.  
  13. ## 関数定義
  14. ### DB connectionを定義
  15. def db_connection(sv=server, db=database, un=username, pw=password):
  16. cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+sv+';DATABASE='+db+';UID='+un+';PWD='+ pw)
  17. return cnxn.cursor()
  18.  
  19. ### SQLを発行
  20. def query_output(sql):
  21. cursor.execute(sql)
  22. row = cursor.fetchone()
  23. while row:
  24. print row[0]
  25. row = cursor.fetchone()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement