10.21

已经完成数据库的连接

点击查看代码
package qixun;

import com.mysql.jdbc.Driver;

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

public class jdbcDemo {
    public static void main(String[] args) throws Exception{
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接
        String url = "jdbc:mysql://localhost:3306/qiii?useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "1234";
        Connection conn=DriverManager.getConnection(url,username,password);
        //定义
        String sql="UPDATE ceeee set money = 6000 where id =2";
        //获取执行
        Statement stmt= conn.createStatement();

        //执行
        int count =stmt.executeUpdate(sql);//受影响的行数

        //处理结果
        System.out.println(count);

        //释放
        stmt.close();
        conn.close();
    }
}

![](https://img2024.cnblogs.com/blog/3474860/202410/3474860-20241021232922913-1925200004.png)
posted @ 2024-10-21 23:29  QixunQiu  阅读(22)  评论(0)    收藏  举报