会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132846个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 18091楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 18092楼
Python 全系列/第五阶段:数据库编程/mysql介绍与环境安装 18094楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 18095楼

老师,麻烦帮我看一下代码,一直显示错误,debug好多次了。谢谢!

JDBC技术2.zip



数据库

image.png


错误提示

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stu_id = 'Smith@hotmail.com'' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1350)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
	at com.bjsxt.dao.impl.BaseDaoImpl.executeUpdate(BaseDaoImpl.java:29)
	at com.bjsxt.dao.impl.StudentDaoImpl.updateStudent(StudentDaoImpl.java:72)
	at service.impl.StudentServiceImpl.modifyStudents(StudentServiceImpl.java:18)
	at com.bjsxt.test.Test.main(Test.java:15)


JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 18097楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 18098楼

# _*_coding=utf-8 _*_
from fake_useragent import UserAgent
import requests
from lxml import etree
from time import sleep

def get_html(url):
    """
    :param url: 要爬取的url
    :return返回html
    """
    headers = {
        "User-Agent": UserAgent().chrome
    }
    resp = requests.get(url, headers=headers)
    sleep(3)
    if resp.status_code == 200:
        resp.encoding = 'utf-8'
        return resp.text
    else:
        return None

def parse_list(html):
    """
    :param html: 传递进来一个有电影列表的html
    :return 返回一个电影列表的url
    """
    e = etree.HTML(html)
    list_url = ['https://maoyan.com'+ url for url in e.xpath('//div[@class="movie-item-hover"]/a/@href')]
    return list_url

def parse_index(html):
    """
    :param html: 传递进来一个有电影信息的url
    :return  已经提取好的电影信息
    """
    e = etree.HTML(html)
    names = e.xpath('//h1/text()')[0]
    type = e.xpath('//li[@class="ellipsis"]/a/text()')[0]
    actor = e.xpath('//ul[@class="celebrity-list clearfix"]/li[@class="celebrity actor"]/div/a/text()')
    actors = format_actor(actor)
    return {'name': names, 'type': type, 'actor': actors}

def format_actor(actors):
    actor_set = set()  # 去重
    for actor in actors:
        actor_set.add(actor.strip())
    return actor_set

def main():
    num = int(input('请输入要获取多少页数据'))
    for y in range(num):
        url = 'https://maoyan.com/films?showType=3&offset={}'.format(y*30)
        # print(url)
        list_html = get_html(url)
        list_url = parse_list(list_html)
        for url in list_url:
            # print(url)
            info_html = get_html(url)
            movie = parse_index(info_html)
            print(movie)


if __name__ == '__main__':
    main()

image.png

老师为啥没有数据啊!

Python 全系列/第十四阶段:Python 爬虫开发/爬虫反反爬- 18102楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 18103楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 18104楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637