软件2班20240513

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

第三次作业
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

package com.yanyu;

import java.sql.*;
import java.util.ResourceBundle;

public class JDBCTest01 {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("com/resources/db");//  ctrl  alt   v
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");

        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
//      注册驱动
        try {
            Class.forName(driver);//ctrl  p
//            获取链接对象
            con = DriverManager.getConnection(url, user, password);
            //        alt   enter
//        ctrl   单机
//        异常(√)    方法未重写(错)
//            System.out.println(con);com.mysql.cj.jdbc.ConnectionImpl@4ae82894
//            关闭自动  提交事务
            con.setAutoCommit(false);

//            操作对象
            st = con.createStatement();
//            SQL语句b
            String sql = "insert into t_user values(1,'yanyu')";
//            执行SQL语句
            st.execute(sql);



//            提交  事务
            con.commit();
        } catch (ClassNotFoundException e) {
//            回滚事务
            if (con != null) {
                try {
                    con.rollback();
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);

        } finally {
//            关流  操作
//              rs   st    con
            if (rs != null) {
//                判断变量 是否为  null
                try {
                    rs.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }

        }


    }
}

driver=com.mysql.cj.jdbc.Driver

key = value

url=jdbc:mysql://127.0.0.1:3306/soft02
user=root
password=root

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值