package cn.jy.demo;
import java.sql.Connection;
import java.sql.SQLException;import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
public class queryrunner {
private static Connection con=JDBCUtilsConfig.getConnection(); public static void main(String[] args) throws SQLException { //insert(); //update(); //delete(); //insert1(); insert2(); } public static void delete() throws SQLException{ QueryRunner qr=new QueryRunner(); String sql="DELETE FROM zhangwu1 WHERE id=?"; int row= qr.update(con,sql,14); System.out.println(row); DbUtils.close(con); } public static void update() throws SQLException{ QueryRunner qr=new QueryRunner(); String sql="UPDATE zhangwu1 SET flname=?,money=?,zhanghu=?,date=?,description=?WHERE id=?"; Object[] param={"杨修","5000","4402","996-2","太差劲","2"}; int row= qr.update(con,sql,param); System.out.println(row); DbUtils.close(con); } public static void insert() throws SQLException{ QueryRunner qr = new QueryRunner(); String sql="INSERT INTO zhangwu1(flname,money,zhanghu,DATE,description)VALUES(?,?,?,?,?)"; Object[] obt={"新垣结衣","90000","4401","1980-2","非常优秀"}; int row =qr.update(con,sql,obt); System.out.println(row); DbUtils.close(con); } public static void insert1() throws SQLException{ QueryRunner qr = new QueryRunner(); String sql="INSERT INTO zhangwu1(flname,money,zhanghu,date,description)values(?,?,?,?,?)"; Object[] obt={"石原里美","90000","4402","1980-9","非常优秀"}; int row= qr.update(con,sql,obt); System.out.println(row); DbUtils.close(con); } public static void insert2() throws SQLException{ QueryRunner qr = new QueryRunner(); String sql="INSERT INTO zhangwu1(flname,money,zhanghu,date,description)values(?,?,?,?,?)"; Object[] obt={"李世民","9000000","4402","880-9","及其优秀"}; int row= qr.update(con,sql,obt); System.out.println(row); DbUtils.close(con); }}