insert 加入append执行后必须commit 或rollback

insert 加入append执行后必须commit 或rollback,否则会出现下列错误:

ORA-12831: Must COMMIT or ROLLBACK after executing INSERT with APPEND hint

*Cause: After executing an INSERT statement with an APPEND hint, a
command other than COMMIT or ROLLBACK was issued.
*Action: Execute COMMIT or ROLLBACK before issuing another SQL command.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8111049/viewspace-624645/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8111049/viewspace-624645/

import requests from bs4 import BeautifulSoup from pprint import pprint import pymysql # 定义函数:将评论数据保存到数据库中 def save_to_navicat(comments): # 创建数据库连接 conn = pymysql.connect(host='localhost', user='root', password='root', db='pa', charset='utf8') # 创建游标对象 cursor = conn.cursor() # 插入数据到 MySQL 数据库中 for comment in comments: sql = ''' INSERT INTO comment (content, author, likes, time, location) VALUES (%s, %s, %s, %s, %s) ''' try: # 执行 SQL 插入语句 cursor.execute(sql, (comment['content'], comment['author'], comment['likes'], comment['time'], comment['location'])) # 提交事务 conn.commit() except Exception as e: # 如果发生异常,回滚事务 conn.rollback() print('Insert error:', e) # 关闭游标和连接 cursor.close() conn.close() for page in range(5): url = "https://movie.douban.com/subject/30391186/comments?start={}&limit=20&sort=new_score&status=P".format(page*20) headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, "html.parser") comments = [] for comment in soup.select(".comment-item"): content = comment.select_one(".comment-content").get_text().strip() author = comment.select_one(".comment-info a").get_text().strip() likes = comment.select_one(".votes").get_text().strip() time = comment.select_one(".comment-time").get_text().strip() location = comment.select_one(".comment-location").contents[-1].strip() comments.append({ "content": content, "author": author, "likes": likes, "time": time, "location": location }) print("第{}页的数据:".format(page+1)) pprint(comments),为什么数据库没有数据,完善代码
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值