Day54 JDBC

Day54 JDBC

JDBC:SUN公司提供的一套操作数据库的标准规范,就是使用Java语言操作关系型数据库的一套API

JDBC与数据库驱动的关系:接口与实现的关系

给大家画一个jdbc的工作模式图

在这里插入图片描述

在这里插入图片描述

1.JDBC的四大金刚

1.DriverManager:用于注册驱动

2.Connection: 表示与数据库创建的连接

3.Statement: 操作数据库sql语句的对象

4.ResultSet: sql语句执行后返回的结果集

2.JDBC操作步骤

1.创建工程,导入驱动jar包

2.注册驱动

Class.forName(“com.mysql.jdbc.Driver”);

3.获取连接

Connection conn = DriverManager.getConnection(url, username, password);

Java代码需要发送SQL给MySQL服务端,就需要先建立连接

Connection(数据库连接对象)作用:

  1. 获取执行 SQL 的对象

2.管理事务

4.定义SQL语句

String sql = “update…” ;

5.获取执行SQL对象

执行SQL语句需要SQL执行对象,而这个执行对象就是Statement对象

Statement stmt = conn.createStatement();

6.执行SQL

stmt.executeUpdate(sql);

ResultSet(结果集对象)作用:封装了SQL查询语句的结果

7.处理返回结果

8.释放资源

创建场景 ----------------------------------------------------------------------------

创建学生表,并添加数据

CREATE TABLE student(
	id INT(3) PRIMARY KEY auto_increment,
	name VARCHAR(32),
	sex VARCHAR(32),
	age INT(3),
	salary FLOAT(8,2),
	course VARCHAR(32)
)
INSERT INTO student(name,sex,age,salary,course) VALUES('龙俊','男',23,10000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('喻平','男',20,12000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('牛西燕','女',19,17000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('刘德华','男',21,15000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('马德华','男',27,10000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('霍建华','男',19,12000,'Java');
INSERT INTO student(name,sex,age,salary,course) VALUES('华晨宇','男',32,5000,'Python');
INSERT INTO student(name,sex,age,salary,course) VALUES('黄日华','男',45,4000,'Python');
INSERT INTO student(name,sex,age,salary,course) VALUES('任达华','男',28,7000,'Python');
INSERT INTO student(name,sex,age,salary,course) VALUES('周华健','男',30,8000,'Python');
INSERT INTO student(name,sex,age,salary,course) VALUES('欧阳震华','男',23,12000,'Python');
INSERT INTO student(name,sex,age,salary,course) VALUES('麻生希','女',30,7000,'HTML');
INSERT INTO student(name,sex,age,salary,course) VALUES('椎名空','女',23,6000,'HTML');
INSERT INTO student(name,sex,age,salary,course) VALUES('水野朝阳','女',28,8000,'HTML');

3.JDBC实现增删改查(最基本)

导包

在这里插入图片描述

项目结构

在这里插入图片描述

测试代码

public class Test01 {

    //添加数据
    @Test
    public void test01() throws ClassNotFoundException, SQLException {
        //导入驱动包
        Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接对象
        String url = "jdbc:mysql://localhost:3306/fy2401javaee?characterEncoding=utf8&serverTimezone=UTC";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "INSERT INTO student(name,sex,age,salary,course) VALUES('京香Julia','女',28,6000,'HTML');";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        statement.close();
        connection.close();
    }


    //删除数据
    @Test
    public void test02() throws ClassNotFoundException, SQLException {

        //导入驱动包
        Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接对象
        String url = "jdbc:mysql://localhost:3306/fy2401javaee?characterEncoding=utf8&serverTimezone=UTC";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "DELETE FROM student WHERE id>10;";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        statement.close();
        connection.close();
    }

    //修改数据
    @Test
    public void test03() throws ClassNotFoundException, SQLException {

        //导入驱动包
        Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接对象
        String url = "jdbc:mysql://localhost:3306/fy2401javaee?characterEncoding=utf8&serverTimezone=UTC";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "UPDATE student SET age=21,salary=50000 WHERE id=3;";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        statement.close();
        connection.close();
    }

    //查询数据
    @Test
    public void test04() throws ClassNotFoundException, SQLException {

        //导入驱动包
        Class.forName("com.mysql.cj.jdbc.Driver");

        //获取连接对象
        String url = "jdbc:mysql://localhost:3306/fy2401javaee?characterEncoding=utf8&serverTimezone=UTC";
        String user = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, user, password);

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令,并获取结果集对象
        String sql = "select * from student";
        ResultSet resultSet = statement.executeQuery(sql);

        //遍历结果集
        while(resultSet.next()){//判断是否有可迭代的数据行

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String sex = resultSet.getString("sex");
            int age = resultSet.getInt("age");
            float salary = resultSet.getFloat("salary");
            String course = resultSet.getString("course");

            System.out.println(id + " -- " + name + " -- " + sex + " -- " + age + " -- " + salary + " -- " + course);
        }

        //关闭资源
        resultSet.close();
        statement.close();
        connection.close();
    }


}

4.资源的正确关闭

Finally ----- 关闭顺序和创建顺序相反

5.创建工具类

1.将变化的配置信息搬到配置文件中

2.工具类提供获取连接的方法

3.工具类提供关闭资源的方法

DBConfig.properties

在这里插入图片描述

driverName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/fy2401javaee?characterEncoding=utf8&serverTimezone=UTCuser
name=root
password=123456

数据库工具类

package com.qf.utils;

public class DBUtil {

    private static String url;
    private static String username;
    private static String password;

    static{
        Properties properties = new Properties();
        try {
            properties.load(DBUtil.class.getClassLoader().getResourceAsStream("DBConfig.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String driverName = properties.getProperty("driverName");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        password = properties.getProperty("password");

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取连接对象
     */
    public static Connection getConnection() throws SQLException {
        Connection connection = DriverManager.getConnection(url,username,password);
        return connection;
    }

    /**
     * 关闭资源
     */
    public static void close(Connection connection, Statement statement, ResultSet resultSet){
        if(resultSet != null){
            try {
                resultSet.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(statement != null){
            try {
                statement.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     * 更新数据(添加、删除、修改)
     */
    public static int commonUpdate(String sql,Object... params) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql);
            paramHandler(statement,params);
            int num = statement.executeUpdate();
            return num;
        }finally {
            close(connection,statement,null);
        }
    }

    /**
     * 添加数据 - 主键回填(主键是int类型可以返回)
     */
    public static int commonInsert(String sql,Object... params) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql,PreparedStatement.RETURN_GENERATED_KEYS);
            paramHandler(statement,params);
            statement.executeUpdate();

            resultSet = statement.getGeneratedKeys();
            int primaryKey = 0;
            if(resultSet.next()){
                primaryKey = resultSet.getInt(1);
            }
            return primaryKey;
        }finally {
            close(connection,statement,resultSet);
        }
    }

    public static <T> List<T> commonQuery(Class<T> clazz,String sql, Object... params) throws SQLException, InstantiationException, IllegalAccessException {

        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;

        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql);
            paramHandler(statement,params);
            resultSet = statement.executeQuery();

            //获取表数据对象
            ResultSetMetaData metaData = resultSet.getMetaData();
            //获取字段个数
            int count = metaData.getColumnCount();

            List<T> list = new ArrayList<>();

            while(resultSet.next()){

                T t = clazz.newInstance();

                //获取字段名及数据
                for (int i = 1; i <= count; i++) {
                    String fieldName = metaData.getColumnName(i);
                    Object fieldVal = resultSet.getObject(fieldName);
                    setField(t,fieldName,fieldVal);
                }
                list.add(t);
            }
            return list;
        } finally {
            DBUtil.close(connection,statement,resultSet);
        }
    }

    /**
     * 处理statement对象参数数据的处理器
     */
    private static void paramHandler(PreparedStatement statement,Object... params) throws SQLException {
        for (int i = 0; i < params.length; i++) {
            statement.setObject(i+1,params[i]);
        }
    }

    /**
     * 获取当前类及其父类的属性对象
     * @param clazz class对象
     * @param name 属性名
     * @return 属性对象
     */
    private static Field getField(Class<?> clazz,String name){

        for(Class<?> c = clazz;c != null;c = c.getSuperclass()){
            try {
                Field field = c.getDeclaredField(name);
                return field;
            } catch (NoSuchFieldException e) {
            } catch (SecurityException e) {
            }
        }
        return null;
    }

    /**
     * 设置对象中的属性
     * @param obj 对象
     * @param name 属性名
     * @param value 属性值
     */
    private static void setField(Object obj,String name,Object value){

        Field field = getField(obj.getClass(), name);
        if(field != null){
            field.setAccessible(true);
            try {
                field.set(obj, value);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

5.1 封装DBUtil - v1.0

package com.qf.jdbc;

public class Test01 {

    //添加数据
    @Test
    public void test01() throws SQLException {
        //获取连接对象
        Connection connection = DBUtil.getConnection();

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "INSERT INTO student(name,sex,age,salary,course) VALUES('京香Julia','女',28,6000,'HTML');";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        DBUtil.close(connection,statement,null);
    }


    //删除数据
    @Test
    public void test02() throws SQLException {
        //获取连接对象
        Connection connection = DBUtil.getConnection();

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "DELETE FROM student WHERE id>10;";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        DBUtil.close(connection,statement,null);
    }

    //修改数据
    @Test
    public void test03() throws SQLException {

        //获取连接对象
        Connection connection = DBUtil.getConnection();

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令
        String sql = "UPDATE student SET age=21,salary=50000 WHERE id=3;";
        int num = statement.executeUpdate(sql);
        System.out.println("对于" + num + "行造成了影响");

        //关闭资源
        DBUtil.close(connection,statement,null);
    }

    //查询数据
    @Test
    public void test04() throws SQLException {

        //获取连接对象
        Connection connection = DBUtil.getConnection();

        //获取发送指令对象
        Statement statement = connection.createStatement();

        //发送SQL指令,并获取结果集对象
        String sql = "select * from student";
        ResultSet resultSet = statement.executeQuery(sql);

        //遍历结果集
        while(resultSet.next()){//判断是否有可迭代的数据行

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String sex = resultSet.getString("sex");
            int age = resultSet.getInt("age");
            float salary = resultSet.getFloat("salary");
            String course = resultSet.getString("course");

            System.out.println(id + " -- " + name + " -- " + sex + " -- " + age + " -- " + salary + " -- " + course);
        }

        //关闭资源
        DBUtil.close(connection,statement,resultSet);
    }

}

5.2 SQL注入问题

select * from student where name=’’ or 1=1 #’ and passwd=‘111111’; #:后面都是注释

出现原因:数据库分不清哪些是sql命令,哪些是数据

解决方案:告诉数据库哪些是sql命令,哪些是数据

需求:模拟登录功能

package com.qf.jdbc02;

public class Test01 {
    public static void main(String[] args) throws SQLException {

        Connection connection = DBUtil.getConnection();

        Statement statement = connection.createStatement();

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入账号:");
        String usernameVal = scan.nextLine();
        System.out.println("请输入密码:");
        String passwordVal = scan.nextLine();

        //select * from user where username='' or 1=1 #' and password='12312345'
        String sql = "select * from user where username='"+usernameVal+"' and password='"+passwordVal+"'";
        ResultSet resultSet = statement.executeQuery(sql);

        if(resultSet.next()){

            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            String nikeName = resultSet.getString("nike_name");

            System.out.println("登录成功");
            System.out.println(username);
            System.out.println(password);
            System.out.println(nikeName);
        }else{
            System.out.println("登录失败");
        }

        DBUtil.close(connection,statement,resultSet);
    }
}

解决方案

采用预编译对象来编程

Statement

PreparedStatement

1.安全性,避免了SQL注入

2.性能,预编译,语句-编译-执行

注意:数据用?表示

package com.qf.jdbc02;

public class Test02 {
    public static void main(String[] args) throws SQLException {

        Connection connection = DBUtil.getConnection();

        String sql = "select * from user where username=? and password=?";
        PreparedStatement statement = connection.prepareStatement(sql);

        //输入数据后,将数据设置给statement对象
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入账号:");
        String usernameVal = scan.nextLine();
        System.out.println("请输入密码:");
        String passwordVal = scan.nextLine();

        statement.setString(1,usernameVal);
        statement.setString(2,passwordVal);

        ResultSet resultSet = statement.executeQuery();

        if(resultSet.next()){

            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            String nikeName = resultSet.getString("nike_name");

            System.out.println("登录成功");
            System.out.println(username);
            System.out.println(password);
            System.out.println(nikeName);
        }else{
            System.out.println("登录失败");
        }

        DBUtil.close(connection,statement,resultSet);
    }
}

* 设置参数值

上面的sql语句中参数使用 ? 进行占位,在之前之前肯定要设置这些 ? 的值。

> PreparedStatement对象:setXxx(参数1,参数2):给 ? 赋值

> * Xxx:数据类型 ; 如 setInt (参数1,参数2)

> * 参数:

> * 参数1: ?的位置编号,从1 开始

> * 参数2: ?的值

* 执行SQL语句

> executeUpdate(); 执行DDL语句和DML语句

> executeQuery(); 执行DQL语句

5.3 jdbc最终版本 封装数据库 - v2.0

增删改都是一样的

在这里插入图片描述

添加数据 - 主键回填(主键是int类型可以返回)

在这里插入图片描述

数据库工具类

 package com.qf.utils;

public class DBUtil {

    private static String url;
    private static String username;
    private static String password;

    static{
        Properties properties = new Properties();
        try {
            properties.load(DBUtil.class.getClassLoader().getResourceAsStream("DBConfig.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String driverName = properties.getProperty("driverName");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        password = properties.getProperty("password");

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取连接对象
     */
    public static Connection getConnection() throws SQLException {
        Connection connection = DriverManager.getConnection(url,username,password);
        return connection;
    }

    /**
     * 关闭资源
     */
    public static void close(Connection connection, Statement statement, ResultSet resultSet){
        if(resultSet != null){
            try {
                resultSet.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(statement != null){
            try {
                statement.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     * 更新数据(添加、删除、修改)
     */
    public static int commonUpdate(String sql,Object... params) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql);
            paramHandler(statement,params);
            int num = statement.executeUpdate();
            return num;
        }finally {
            close(connection,statement,null);
        }
    }

    /**
     * 添加数据 - 主键回填(主键是int类型可以返回)
     */
    public static int commonInsert(String sql,Object... params) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;
        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql,PreparedStatement.RETURN_GENERATED_KEYS);
            paramHandler(statement,params);
            statement.executeUpdate();

            resultSet = statement.getGeneratedKeys();
            int primaryKey = 0;
            if(resultSet.next()){
                primaryKey = resultSet.getInt(1);
            }
            return primaryKey;
        }finally {
            close(connection,statement,resultSet);
        }
    }

    public static <T> List<T> commonQuery(Class<T> clazz,String sql, Object... params) throws SQLException, InstantiationException, IllegalAccessException {

        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;

        try {
            connection = getConnection();
            statement = connection.prepareStatement(sql);
            paramHandler(statement,params);
            resultSet = statement.executeQuery();

            //获取表数据对象
            ResultSetMetaData metaData = resultSet.getMetaData();
            //获取字段个数
            int count = metaData.getColumnCount();

            List<T> list = new ArrayList<>();

            while(resultSet.next()){

                //创建对象
                T t = clazz.newInstance();

                //获取字段名及数据
                for (int i = 1; i <= count; i++) {
                    String fieldName = metaData.getColumnName(i);
                    Object fieldVal = resultSet.getObject(fieldName);
                    setField(t,fieldName,fieldVal);
                }
                list.add(t);
            }
            return list;
        } finally {
            DBUtil.close(connection,statement,resultSet);
        }
    }

    /**
     * 处理statement对象参数数据的处理器
     */
    private static void paramHandler(PreparedStatement statement,Object... params) throws SQLException {
        for (int i = 0; i < params.length; i++) {
            statement.setObject(i+1,params[i]);
        }
    }

    //下面是反射的内容
    /**
     * 获取当前类及其父类的属性对象
     * @param clazz class对象
     * @param name 属性名
     * @return 属性对象
     */
    private static Field getField(Class<?> clazz,String name){

        for(Class<?> c = clazz;c != null;c = c.getSuperclass()){
            try {
                Field field = c.getDeclaredField(name);
                return field;
            } catch (NoSuchFieldException e) {
            } catch (SecurityException e) {
            }
        }
        return null;
    }

    /**
     * 设置对象中的属性
     * @param obj 对象
     * @param name 属性名
     * @param value 属性值
     */
    private static void setField(Object obj,String name,Object value){

        Field field = getField(obj.getClass(), name);
        if(field != null){
            field.setAccessible(true);
            try {
                field.set(obj, value);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

学生类

package com.qf.jdbc03;

public class Student {

    private int id;
    private String name;
    private String sex;
    private int age;
    private float salary;
    private String course;

  //无参构造,有参构造,set,get,tostring省略

测试类 封装数据库 - v2.0

package com.qf.jdbc03;

public class Test01 {
    /**
     * 知识点:封装数据库 - v2.0
     */

    //添加数据
    @Test
    public void test01() throws SQLException {
        String sql = "INSERT INTO student(name,sex,age,salary,course) VALUES(?,?,?,?,?)";
        int num = DBUtil.commonUpdate(sql, "天使萌", "女", 23, 10000, "HTML");
        System.out.println("对于" + num + "行造成了影响");
    }

    //删除数据
    @Test
    public void test02() throws SQLException {
        String sql = "delete from student where id=?";
        int num = DBUtil.commonUpdate(sql, 3);
        System.out.println("对于" + num + "行造成了影响");
    }

    //修改数据
    @Test
    public void test03() throws SQLException {
        String sql = "update student set salary=? where id=?";
        int num = DBUtil.commonUpdate(sql, 15000,1);
        System.out.println("对于" + num + "行造成了影响");
    }

    //添加数据 -
    @Test
    public void test04() throws SQLException {
        String sql = "INSERT INTO student(name,sex,age,salary,course) VALUES(?,?,?,?,?)";
        int primaryKey = DBUtil.commonInsert(sql, "铃原爱蜜莉", "女", 23, 10000, "HTML");
        System.out.println("返回的主键是:" + primaryKey);
    }

    //查询数据
    @Test
    public void test05() throws SQLException, InstantiationException, IllegalAccessException {
        String sql = "select * from student where id<?";
        List<Student> list = DBUtil.commonQuery(Student.class, sql, 8);
        for (Student stu : list) {
            System.out.println(stu);
        }
    }
}

intln(“对于” + num + “行造成了影响”);
}

//修改数据
@Test
public void test03() throws SQLException {
    String sql = "update student set salary=? where id=?";
    int num = DBUtil.commonUpdate(sql, 15000,1);
    System.out.println("对于" + num + "行造成了影响");
}

//添加数据 -
@Test
public void test04() throws SQLException {
    String sql = "INSERT INTO student(name,sex,age,salary,course) VALUES(?,?,?,?,?)";
    int primaryKey = DBUtil.commonInsert(sql, "铃原爱蜜莉", "女", 23, 10000, "HTML");
    System.out.println("返回的主键是:" + primaryKey);
}

//查询数据
@Test
public void test05() throws SQLException, InstantiationException, IllegalAccessException {
    String sql = "select * from student where id<?";
    List<Student> list = DBUtil.commonQuery(Student.class, sql, 8);
    for (Student stu : list) {
        System.out.println(stu);
    }
}

}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/713290.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Quartus 13.0】NIOS II 部署UART 和 PWM

打算在 EP1C3T144I7 芯片上部署 nios ii 做 uart & pwm控制 这个芯片或许不够做 QT 部署 这个芯片好老啊&#xff0c;但是做控制足够了&#xff0c;我只是想装13写 leader给的接口代码是用VHDL写的&#xff0c;我不会 当然verilog我也不太会 就这样&#xff0c;随便写吧 co…

SUSTAINABILITY,SCIESSCI双检期刊还能投吗?

本期&#xff0c;小编给大家介绍的是一本MDPI出版社旗下SCIE&SSCI双检“毕业神刊”——SUSTAINABILITY。据悉&#xff0c;早在2024年1月&#xff0c;ElSEVIER旗下的Scopus数据库已暂停收录检索期刊SUSTAINABILITY所发表文章&#xff0c;同时重新评估是否继续收录该期刊。随…

Qwen2——阿里巴巴最新的多语言模型挑战 Llama 3 等 SOTA

引言 经过几个月的期待&#xff0c; 阿里巴巴 Qwen 团队终于发布了 Qwen2 – 他们强大的语言模型系列的下一代发展。 Qwen2 代表了一次重大飞跃&#xff0c;拥有尖端的进步&#xff0c;有可能将其定位为 Meta 著名的最佳替代品 骆驼3 模型。在本次技术深入探讨中&#xff0c;我…

零基础入门学用Arduino 第三部分(三)

重要的内容写在前面&#xff1a; 该系列是以up主太极创客的零基础入门学用Arduino教程为基础制作的学习笔记。个人把这个教程学完之后&#xff0c;整体感觉是很好的&#xff0c;如果有条件的可以先学习一些相关课程&#xff0c;学起来会更加轻松&#xff0c;相关课程有数字电路…

python-基础篇-类与对象/面向对象程序设计-是什么

文章目录 定义一&#xff1a;面对对象是一种编程思想定义一&#xff1a;面向对象是一种抽象1、面向对象的两个基本概念2、面向对象的三大特性 定义一&#xff1a;你是土豪&#xff0c;全家都是土豪面向对象编程基础类和对象定义类创建和使用对象访问可见性问题面向对象的支柱 定…

C++初学者指南第一步---4.基本类型

C初学者指南第一步—4.基本类型 文章目录 C初学者指南第一步---4.基本类型1.变量声明2.快速概览Booleans 布尔型Characters 字符型Signed Integers 有符号整数Unsigned Integers 无符号整数Floating Point Types 浮点数类型 3.Common Number Representations 常用的数字表示常用…

用Copilot画漫画,Luma AI生成视频:解锁创意新玩法

近年来&#xff0c;随着人工智能技术的不断发展&#xff0c;各种创意工具也层出不穷。今天&#xff0c;我们就来介绍一种全新的创作方式&#xff1a;使用Copilot画漫画&#xff0c;再将漫画放入Luma AI生成视频。 Copilot&#xff1a;你的AI绘画助手 Copilot是一款基于人工智…

【Kubernetes项目部署】k8s集群+高可用、负载均衡+防火墙

项目架构图 &#xff08;1&#xff09;部署 kubernetes 集群 详见&#xff1a;http://t.csdnimg.cn/RLveS &#xff08;2&#xff09; 在 Kubernetes 环境中&#xff0c;通过yaml文件的方式&#xff0c;创建2个Nginx Pod分别放置在两个不同的节点上&#xff1b; Pod使用hostP…

TCP及UDP协议

tcp是点到点的&#xff0c;只有一条路径&#xff0c;到达顺序和发送顺序是相同的 回复的确认号是序发送端的序列号加上data的长度 1910 发送端的序列号也是那么算的 ack和下一个seq一样 那就没问题 三次握手四次挥手&#xff1a; 为啥是三次呢&#xff1f; 假如一次&#xf…

SpringBoot使用jasypt实现数据库信息的脱敏,以此来保护数据库的用户名username和密码password(容易上手,详细)

1.为什么要有这个需求&#xff1f; 一般当我们自己练习的时候&#xff0c;username和password直接是爆露出来的 假如别人路过你旁边时看到了你的数据库账号密码&#xff0c;他跑到他的电脑打开navicat直接就是一顿连接&#xff0c;直接疯狂删除你的数据库&#xff0c;那可就废…

学习笔记——网络管理与运维——SNMP(SNMP架构)

三、SNMP架构 1、SNMP结构概述 SNMP被设计为工作在TCP/IP协议族上&#xff0c;基于TCP/IP协议工作&#xff0c;对网络中支持SNMP协议的设备进行管理。所有支持SNMP协议的设备都提供SNMP这个统一界面&#xff0c;使得管理员可以使用统一的操作进行管理&#xff0c;而不必理会设…

基于Spring+Vue的前后端分离的计算器

麻雀虽小&#xff0c;五脏俱全 该项目已部署上线&#xff1a;http://calculator.wushf.top/ 并通过Gitee Go流水线实现持续部署。 需求分析 表达式求值 支持加减乘除四则运算、支持高精度 获取日志 Api文档定义 前后端分离&#xff0c;人不分离 通过Apifox定义接口细节&#…

「TCP 重要机制」三次握手四次挥手

&#x1f387;个人主页&#xff1a;Ice_Sugar_7 &#x1f387;所属专栏&#xff1a;计网 &#x1f387;欢迎点赞收藏加关注哦&#xff01; 三次握手&四次挥手 &#x1f349;连接管理&#x1f34c;三次握手&#x1f34c;意义&#x1f34c;四次挥手&#x1f34c;TCP 状态转换…

深入分析 Android BroadcastReceiver (三)

文章目录 深入分析 Android BroadcastReceiver (三)1. 广播消息的优缺点及使用场景1.1 优点1.2 缺点 2. 广播的使用场景及代码示例2.1. 系统广播示例&#xff1a;监听网络状态变化 2.2. 自定义广播示例&#xff1a;发送自定义广播 2.3. 有序广播示例&#xff1a;有序广播 2.4. …

[算法刷题—二分法]寻找插入位置

题目展示: 本道题本身并不是很难,主要是学习和分析二分查找插入位置的方法。 首先大体上分为两种情况: 一.target在待查找的数组之中,返回对应值的下标索引。 二.target不在待查找的数组之中&#xff0c;需要返回target插入位置的索引(原数组有序) 第一种情况不难&#xff…

跟着AI学AI_08 NumPy 介绍

NumPy&#xff08;Numerical Python&#xff09;是一个用于科学计算的基础库&#xff0c;它为 Python 提供了支持大规模多维数组和矩阵 NumPy 介绍 NumPy&#xff08;Numerical Python&#xff09;是一个用于科学计算的基础库&#xff0c;它为 Python 提供了支持大规模多维数…

最新版点微同城源码34.7+全套插件+小程序前后端(含安装教程)

模板挺好看的 带全套插件 自己耐心点配置一下插件 可以H5可以小程序 源码下载&#xff1a;https://download.csdn.net/download/m0_66047725/89394996 更多资源下载&#xff1a;关注我。

【单元测试】Spring Boot 的测试库

Spring Boot 的测试库 1.了解回归测试框架 JUnit2.了解 assertThat3.了解 Mockito4.了解 JSONPath5.测试的回滚 单元测试&#xff08;unit test&#xff09;是为了检验程序的正确性。一个单元可能是单个 程序、类、对象、方法 等&#xff0c;它是应用程序的最小可测试部件。 单…

ATMEGA16读写24C256

代码&#xff1a; #include <mega16.h> #include <stdio.h> #include <i2c.h> #include <delay.h> // Declare your global variables here #define EEPROM_BUS_ADDRESS 0xa0 #asm.equ __i2c_port0x15.equ __sda_bit1 .equ __scl_bit0 #endasm uns…

课设--学生成绩管理系统(二)

欢迎来到 Papicatch的博客 目录 &#x1f40b;引言 &#x1f988;编写目的 &#x1f988;项目说明 &#x1f40b;产品介绍 &#x1f988;产品概要说明 &#x1f988;产品用户定位 &#x1f988;产品中的角色 &#x1f40b; 产品总体业务流程图 &#x1f40b; 产品功…