pyodbc数据库访问

 

cnxn = pyodbc.connect("Driver={SQL Server};Server=localhost;Database=reportdb;uid="+v_user+";pwd="+v_pwd)

cursor = cnxn.cursor()
cursor.execute("select * from config where type_id='gh_zhjy'")

users=[]
for row in cursor: 
    users.append(row[3])  

list=[];
filename=file_path;
fp=open(filename,"r",encoding='utf-8');
done=False;
while not done:
   aline=fp.readline();   
   if(aline!=""):
       aline=aline.replace('\n','').replace(" ","");
       if(aline in users):
         list.append('浙江国华浙能发电有限公司:'+aline.replace('\n','')); 
   else:
     done=True;
fp.close();
print(list);

 

上一篇:pandas,读取或存储DataFrames的数据到mysql中


下一篇:python读取SQLServer数据库的image格式数据并导出为图片