JDBC的使用

练习

  1. account表 添加一条记录
  2. account表 修改记录
  3. account表 删除一条记录
/**
 * account表 添加一条记录 insert 语句
 */
public class JDBCDemo2 {
    public static void main(String[] args) {
        Statement stmt = null;
        Connection conn = null;
        try {
            //1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2. 定义sql
            String sql = "insert into account values(null,'王五',3000)";
            //3.获取Connection对象
            conn = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");
            //4.获取执行sql的对象 Statement
            stmt = conn.createStatement();
            //5.执行sql
            int count = stmt.executeUpdate(sql);//影响的行数
            //6.处理结果
            System.out.println(count);
            if(count > 0){
                System.out.println("添加成功!");
            }else{
                System.out.println("添加失败!");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //stmt.close();
            //7. 释放资源
            //避免空指针异常
            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
/**
 * account表 修改记录
 */
public class JDBCDemo3 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try {
            //1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2.获取连接对象
            conn = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");
            //3.定义sql
            String sql  = "update account set balance = 1500 where id = 3";
            //4.获取执行sql对象
            stmt = conn.createStatement();
            //5.执行sql
            int count = stmt.executeUpdate(sql);
            //6.处理结果
            System.out.println(count);
            if(count > 0){
                System.out.println("修改成功!");
            }else{
                System.out.println("修改失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //7.释放资源

            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

/**
 * account表 删除一条记录
 */
public class JDBCDemo4 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try {
            //1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2.获取连接对象
            conn = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");
           //conn = JDBCUtils.getConnection("jdbc:mysql:///db3", "root", "root");
            //3.定义sql
            String sql  = "delete from account where id = 3";
            //4.获取执行sql对象
            stmt = conn.createStatement();
            //5.执行sql
            int count = stmt.executeUpdate(sql);
            //6.处理结果
            System.out.println(count);
            if(count > 0){
                System.out.println("删除成功!");
            }else{
                System.out.println("删除失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //7.释放资源

            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

资源下载链接为: https://pan.quark.cn/s/00cceecb854d 这个项目名为“mnist-nnet-hls-zynq7020-fpga prj”,是一个与机器学习相关的工程,专注于利用高级综合(HLS)技术将针对MNIST数据集设计的神经网络(nnet)实现在Zynq 7020 FPGA平台上,以加速图像识别任务。项目提供的压缩包包含所有相关代码文件,如C/C++源码、HLS接口定义、Vivado HLS项目文件、硬件描述语言代码(Verilog或VHDL)及配置文件等,用户可通过这些代码理解、实现或修改设计流程。 项目标签“mnist-nnet-hls-z”一步明确了其关注点:MNIST数据集、HLS技术以及Zynq目标平台。MNIST是用于手写数字识别的知名训练数据集;HLS可将高级编程语言转化为硬件描述语言;Zynq 7020是Xilinx的SoC FPGA,融合了ARM处理器与可编程逻辑。文件名中提到的“vivado”指的是Xilinx的Vivado设计套件,它是一个用于FPGA设计、实现、仿真和调试的集成开发环境,其中的Vivado HLS工具能够将C、C++或SystemC编写的算法自动转换为硬件描述语言代码。 项目可能的实施步骤如下:首先,对MNIST数据集行预处理,如归一化、降维等,使其适配神经网络模型输入;其次,构建适用于手写数字识别的神经网络模型,例如卷积神经网络(CNN)或全连接网络(FCN);接着,运用HLS工具将神经网络模型转化为硬件描述,并优化性能与资源利用率;然后,在Vivado环境中,将生成的硬件描述代码映射到Zynq 7020的FPGA部分,行时序分析与综合优化;此外,由于Zynq是SoC,包含处理器系统,还需编写控制软件来管理与调度FPGA上的硬件加速器,可能涉及OpenCV、OpenCL等库的使用;之后,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值