都是用executeUpdate方法
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Statement;
public class JDbc {
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
Class.forName("com.mysql.jdbc.Driver");//加载Driver类
connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test02","root","root");//链接数据库
statement = (Statement) connection.createStatement();//新建Statement接口
String sql1 = "insert into tb_peo(id, name, birthday) values('5','郭珂','1999-8-10')";
//insert into 表名(表中列名1,列名2,...) values('',''....)
int a = statement.executeUpdate(sql1);
System.out.println("表中有"+a+"行被修改");
String sql2 = "update tb_peo set birthday = '1999-8-11'where id = 5";
//update 表名 set 列名 = '修改值' where = ;
int b = statement.executeUpdate(sql2);
System.out.println("表中有"+b+"行被修改");
String sql3 = "delete from tb_peo where id = 5";
//delete from 表名 where = ;
int c = statement.executeUpdate(sql3);
System.out.println("表中有"+c+"行被修改");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
statement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}