###_*_coding:gb2312_*_
from Tkinter import *
import sys
import DB2
class ONE(object):
def __init__(self):
self.top=Tk()
self.top.title('test')
self.IDVar1=StringVar()
self.IDVar2=StringVar()
frame=Frame(self.top)
IDLabel1=Label(frame,text="code:",underline=0)
IDLabel2=Label(frame,text="Userid:",underline=0)
IDEntry1=Entry(frame,textvariable=self.IDVar1,width=25)
IDEntry2=Entry(frame,textvariable=self.IDVar2,width=25)
def check():
dsn="driver={IBM DB2 ODBC DRIVER};database=%s;hostname=%s;port=%s;protocol=tcpip;"%("dbname","192.168.1.1","65535")
conn = DB2.connect(dsn,"user","password")
curs = conn.cursor() #到此为止都很顺利
curs.execute("select * from tables where userid=%s and code=%s")%(IDEntry2.get(),%IDEntry1.get()) #Entry获取的值无法当成变量传递给execute的sql语句中。
#curs.execute("select * from tables where userid=‘aaa’ and code=‘123’") //直接写死就可以
ows = curs.fetchall()
print ows
curs.close()
conn.close()
Button1=Button(frame,text="check",command=check)
IDLabel1.grid(row=0,column=0,sticky=W,pady=3,padx=15)
IDEntry1.grid(row=0,column=1,sticky=EW,pady=3,padx=15)
Button1.grid(row=2,column=1,sticky=EW,pady=3,padx=3)
frame.pack()
def close(self,event=None):
quit()
def main():
ONE()
mainloop()
if __name__=='__main__':
main()
侃侃尔雅
莫回无
相关分类