使用 Statement 接口实现添加数据操作
eg:DbUtil类为上一个博客写的
package chap03.sec02;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import util.DbUtil;
public class Demo1 {
public static void main(String[] args) throws SQLException {
DbUtil dbUtil=new DbUtil();
String sql="insert into t_book values(null,'java酷哥',100,'张三',1)";
Connection con=dbUtil.getCon();
Statement stmt=con.createStatement();
int result=stmt.executeUpdate(sql);
System.out.println("操作的结果:"+result+"数据");
stmt.close();
dbUtil.closeCon(con);
}
}