码迷,mamicode.com
首页 > 数据库 > 详细

DbUtils类的添加,修改,删除

时间:2019-02-26 15:39:57      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:jdbc   zhang   esc   etc   rgs   utils   nbsp   import   oid   

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);
}
}

DbUtils类的添加,修改,删除

标签:jdbc   zhang   esc   etc   rgs   utils   nbsp   import   oid   

原文地址:https://www.cnblogs.com/Fisherman13/p/10437218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!