[Tutor] put query result set into dictionary
Shawn Matlock
matlocs at odscompanies.com
Wed Nov 10 23:18:48 CET 2010
Let's see if I can ask the right questions the right way. I am trying to put the results of a MySQL query into a dictionary. It fails because it includes the Unicode delimiter - "u'somevalue'". Can someone tell me the right way to do this, please?
Thank you,
Shawn
csdbConn = zxJDBC.connect("jdbc:mysql://myhost:3306/mydb", "User", "Password", "com.mysql.jdbc.Driver")
csdbCursor = csdbConn.cursor(1)
envsql = "select envVariable, envValue from ODS_ENV_DICT where envName = 'ST2'"
print 'envsql: ' + envsql
csdbCursor.execute(envsql)
envDict = {}
for envVariable, envValue in csdbCursor.fetchall():
print envVariable, envValue
envDict[envVariable].append(envValue)
csdbCursor.close()
csdbConn.close()
------------------
envsql: select envVariable, envValue from ODS_ENV_DICT where envName = 'ST2'
envDB systest2
Traceback (most recent call last):
File "H:\workspace\test\src\root\nested\example.py", line 33, in <module>
envDict[envVariable].append(envValue)
KeyError: u'envDB'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101110/1d78dae4/attachment.html>
More information about the Tutor
mailing list