Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

How can I write result into MySQL? #179

Open
ghost opened this issue May 10, 2016 · 0 comments
Open

How can I write result into MySQL? #179

ghost opened this issue May 10, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented May 10, 2016

I submited the jar packege,topology can be normal operation. but can't write the result into MySQL and can get the log.I have already create a table in my database called result
`#coding=utf-8
import MySQLdb
import logging

from pyleus.storm import SimpleBolt

log = logging.getLogger('log_results')

def write_result(freqset,count):
conn = MySQLdb.connect(host='10.1.1.5',user='root',passwd='',db='datamining',port=3306)
cur = conn.cursor()
st = ''
for i in freqset:
st = st + i + ','
sql = "select * from result where freqset = " + "'"+ st +"'"
cur.execute(sql)
returned_value = cur.fetchone()
if returned_value != None:
supnum = returned_value[1]+count
sql1 = "update result set supnum = %s where freqset = '%s';" %(str(supnum),st)
cur.execute(sql1)
conn.commit
else:
value = [st,count]
sql2 = 'insert into result values(%s,%s)'
cur.execute(sql2,value)
conn.commit()

cur.close()
conn.close()

class LogResultsBolt(SimpleBolt):

def process_tuple(self, tup):
    freqset, count = tup.values
    log.debug("%s: %d", freqset, count)
    write_result(freqset, count)

if name == 'main':
logging.basicConfig(
level=logging.DEBUG,
filename='/tmp/results.log',
format="%(message)s",
filemode='a',
)

LogResultsBolt().run()

`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants