会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132490个问题
Python 全系列/第一阶段:Python入门/Python入门(动画版) 22670楼

mport java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC工具类
 */
public class JDBCUtil {
   
    private static String driver = "com.mysql.jbdc.Driver";
    private static String jdbcUrl = "jdbc:mysql://localhost:3306/bjsxt?useUnicode=true&characterEncoding=utf-8";
    private static String username = "root";
    private static String userpassword = "rsc125979";
    static {
        // 注册驱动
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    // 获取Connection对象
    public static Connection getConnection(){
        // 创建连接
        Connection  conn =null;
        try {
            conn = DriverManager.getConnection(jdbcUrl,username,userpassword);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    // 关闭Statement
    public static void closeStatement(Statement state){
        if(state != null){
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    // 关闭Connection
    public static void closeConnection(Connection conn){
        if(conn != null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    // 关闭资源  将关闭Connection和Statement方法放到一起
    public static void closeResource(Statement state,Connection conn){
        closeStatement(state);
        closeConnection(conn);

    }

}

public class JDBXTest 

    // 更新departments表中department_id为6的数据
    public void updateDepartments(String department_name,int location_id,int department_id){
        Connection conn = null;
        Statement state = null;
        try{
            conn = JDBCUtil.getConnection();
            state = conn.createStatement();
            // sql语句
            String sql = "update departments d set d.department_name = '"+department_name+"',d.location_id="+location_id+" where d.department_id = "+department_id+" ";
            // 执行sql语句
            int flag = state.executeUpdate(sql);
            System.out.println(flag);
        }catch(Exception e) {
            e.printStackTrace();
        } finally{
            JDBCUtil.closeResource(state,conn);
        }
    }
    public static void main(String[] args) {
        JDBXTest test = new JDBXTest();
       test.updateDepartments("IT",6,11);
    }


}

image.png

image.png

语句执行成功了,但是为什么会报异常呀,没有使用工具类时更新数据没有报异常

报错的位置分别是

JDBCUtil中的

Class.forName(driver);

JDBCTest中的

conn = JDBCUtil.getConnection();
和
test.updateDepartments("IT",6,11);


JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 22671楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 22672楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>魅族</title>
    <style>
        .box-header{
            width: 100%;
            height: 680px;
            background: url("魅族images/444c6b0f-a71c-4e91-8c17-6745223228c5.jpg") no-repeat center ;
            background-size: cover;
        }
        .box-phone{
            width: 100%;
            height: 450px;
            background: url("魅族images/a6c64f8f-6ab5-4a93-8139-2a893eb2a2a5.jpg") no-repeat center;
            background-size: cover;
        }
        .box-header-bottom{
            width: 1262px;
            height: 277px;
            /*background: red;*/
        }
        .box-top{
            width: 25%;
            height: 100%;
            /*background: orange;*/
            float: left;
        }
        .img1{
            width: 130px;
            height: 130px;
        }
        .box-top>p:first-of-type,.phone-top-left>p:first-of-type,.phone-top-right>p:first-of-type,.phone-bottom-items>p:first-of-type{
            font-size: 20px;
            font-weight: bold;
            width: 310px;
            height: 30px;
        }
        .box-top>p:last-child,.phone-top-left>p:first-of-type+p,.phone-top-right>p:first-of-type+p,.phone-bottom-items>p:last-of-type{
            color: #999999;
            font-size: 14px;
            width: 310px;
            height: 21px;
        }
        .title{
            text-align: center;
            font-weight: bold;
            font-size: 2em;
        }
        .box-phone-bottom{
            width: 1262px;
            height: 1005px;
        }
        .box-phone-bottom-center{
            width: 1230px;
            height:1220px;
        }
        .phone-top{
            width:1230px;
            height: 610px;
        }
        .phone-bottom{
            width: 1212px;
            height: 375px;
        }
        .phone-top-left,.phone-top-right{
            width: 615px;
            height: 610px;
            float: left;
        }
        .phone-bottom-items{
            width: 303px;
            height: 375px;
            float: left;
        }
        .img2{
            width: 460px;
            height: 460px;
        }
        .price{
            width: 71px;
            height: 33px;
            color: red;
            font-size: 28px;
        }
        .price1{
            width: 14px;
            height: 21px;
            font-size: 12px
        }
        .img3{
         width: 230px;
            height: 230px;
        }
/*.img+p{
    font-size: 20px;
    font-weight: bold;
}*/
    </style>
</head>
<body>
<div class="box-header">
    <a href="https://www.meizu.com/">
    </a>
</div>
<div class="box-header-bottom">
    <div class="box-top" align="center">
        <img src="魅族images/5f896683-d2f2-487d-a296-722fc9e17f1e.png" alt="" class="img1">
        <p>魅族 18</p>
        <p>立省900 + 12 期免息 + 赠手机壳</p>
    </div>
    <div class="box-top" align="center">
        <img src="魅族images/5f896683-d2f2-487d-a296-722fc9e17f1e.png" alt="" class="img1">
        <p>魅族 18</p>
        <p>立省900 + 12 期免息 + 赠手机壳</p>
    </div>
    <div class="box-top" align="center">
        <img src="魅族images/5f896683-d2f2-487d-a296-722fc9e17f1e.png" alt="" class="img1">
        <p>魅族 18</p>
        <p>立省900 + 12 期免息 + 赠手机壳</p>
    </div>
    <div class="box-top" align="center">
        <img src="魅族images/5f896683-d2f2-487d-a296-722fc9e17f1e.png" alt="" class="img1">
        <p>魅族 18</p>
        <p>立省900 + 12 期免息 + 赠手机壳</p>
    </div>
</div>
<h3 class="title">手机</h3>
<div class="box-phone">
</div>
<div class="box-phone-bottom">
    <div class="box-phone-bottom-center">
        <div class="phone-top" >
            <div class="phone-top-left" align="center">
                <p>魅族 18</p>
                <p>限时领券至高立省900 | 赠手机壳</p>
                <p class="price"><span class="price1">¥</span>3999</p>
                <img src="魅族images/de87d38d-3785-4605-a211-71364ded123f.png" alt=""  class="img2">
            </div>
            <div class="phone-top-right" align="center">
                <p>魅族 18</p>
                <p>限时领券至高立省900 | 赠手机壳</p>
                <p class="price"><span class="price1">¥</span>3999</p>
                <img src="魅族images/de87d38d-3785-4605-a211-71364ded123f.png" alt=""  class="img2">
            </div>
        </div>
        <div class="phone-bottom">
            <div class="phone-bottom-items" align="center">
                <img src="魅族images/Cgbj0F6zwMuANEeWAAw6yQFAJXM097.png" alt="" class="img3">
                <p>魅族 17「AG梦幻独角兽」</p>
                <p>高通骁龙 865 | 120 Hz尝鲜模式</p>
                <p class="price"><span class="price1">¥</span> 3699</p>
            </div>
            <div class="phone-bottom-items" align="center">
                <img src="魅族images/Cgbj0F6zwMuANEeWAAw6yQFAJXM097.png" alt="" class="img3">
                <p>魅族 17「AG梦幻独角兽」</p>
                <p>高通骁龙 865 | 120 Hz尝鲜模式</p>
                <p class="price"><span class="price1">¥</span>3699</p>
            </div>
            <div class="phone-bottom-items" align="center">
                <img src="魅族images/Cgbj0F6zwMuANEeWAAw6yQFAJXM097.png" alt="" class="img3">
                <p>魅族 17「AG梦幻独角兽」</p>
                <p>高通骁龙 865 | 120 Hz尝鲜模式</p>
                <p class="price"><span class="price1">¥</span> 3699</p>
            </div>
            <div class="phone-bottom-items" align="center">
                <img src="魅族images/Cgbj0F6zwMuANEeWAAw6yQFAJXM097.png" alt="" class="img3">
                <p>魅族 17「AG梦幻独角兽」</p>
                <p>高通骁龙 865 | 120 Hz尝鲜模式</p>
                <p class="price"><span class="price1">¥</span> 3699</p>
            </div>
        </div>
    </div>
</div>
</body>
</html>

老师,我写魅族官网写了一部分,为什么价格哪里class都一样,但是设置不出来同样的样式呢?

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS常用属性 22674楼


微信截图_20230728153941.png

JAVA 全系列/第十八阶段:亿级高并发电商项目/亿级高并发电商项目(旧) 22675楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 22676楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 22678楼
WEB前端全系列/第十阶段:Nodejs编程模块/Express框架 22679楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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