当前位置:网站首页>Statement执行update语句

Statement执行update语句

2022-08-02 00:02:00 Camellia——

package com.lin.jdbc_01;

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

/*
 * 使用Statement操作DML,updata语句
 * */
public class JdbcDemo1 {
	public static void main(String[] args) throws Exception {
		//1)注册驱动
		Class.forName("com.mysql.jdbc.Driver");
//		2)获取数据库连接对象
		Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb_01", "root", "123456");
//		3)准备sql
		String sql="update stu set name='王五' where id=4;";
//		4)创建执行对象
		Statement stmt=conn.createStatement();
//		5)执行
		int count=stmt.executeUpdate(sql);
		System.out.println(count);
//		6)释放资源
		stmt.close();
		conn.close();
	}

}

原网站

版权声明
本文为[Camellia——]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_57219176/article/details/126110565