数据库操作:删除和修改数据

增加,删除,修改  都属于更新操作,都会修改数据库里面的内容,所以都使用execute方法

查询 使用executeQuery方法

package SQl;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import cn.xtnotes.unit.GetConnetion;

public class T4_deleUP {

	public static void main(String[] args) {
		Connection conn=null;
		Statement stmt=null;
		conn=GetConnetion.getConn();
		String sql1="delete from stu where name='小米'";
		String sql2="update stu set name='张三2' where id=1 ";
		try {
			stmt=conn.createStatement();
			stmt.execute(sql1);
			stmt.execute(sql2);
			System.out.println("执行成功");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

运行结果

阅读剩余
THE END