修改和删除
package com.hqy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JDBCDemo04 {
public static void main(String[] args) throws Exception{
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//获取连接
String url = "jdbc:mysql://localhost:3306/mydb1?characterEncoding=utf8&useSSL=false";
Connection conn = DriverManager.getConnection(url, "root", "123456");
//创建命令
Statement state = conn.createStatement();
//修改
/* int i = state.executeUpdate("update hqy set name='路明非' where id= 1");
if(i>0){
System.out.println("执行成功");
}else{
System.out.println("执行失败");
}*/
//删除
int y = state.executeUpdate("delete from hqy where id=2");
if(y>0){
System.out.println("执行成功");
}else{
System.out.println("执行失败");
}
//关闭
state.close();
conn.close();
System.out.println("关闭成功");
}
}