dbutils是apache封装了JDBC的工具类,比mysql-connector更方便些

下载地址:http://commons.apache.org/proper/commons-dbutils/download_dbutils.cgi

database.properties:

driver = com.mysql.jdbc.Driver
url = jdbc:mysql://192.168.0.207:3306/mydb
user = root
pwd = Console.Write21
package cn.sasa.demo5;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties; public class DBProperties {
public static String driver = "";
public static String url = "";
public static String user = "";
public static String pwd = ""; static {
// 类的加载器
try {
InputStream input = DBProperties.class.getClassLoader().getResourceAsStream("database.properties");
Properties properties = new Properties();
properties.load(input);
driver = properties.getProperty("driver");
url = properties.getProperty("url");
user = properties.getProperty("user");
pwd = properties.getProperty("pwd");
}catch(IOException ex) { }
} public static Connection getConnection() throws SQLException, ClassNotFoundException {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pwd);
return conn;
}
}
package cn.sasa.demo5;

import java.sql.Connection;
import java.sql.SQLException; import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner; public class QueryRunnerDemo {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Connection conn =DBProperties.getConnection(); //创建QueryRunner对象
QueryRunner query = new QueryRunner(); // String sql = "INSERT INTO `product` (`pname`, `price`, `ptype`) VALUES ( ?, ?, ?);";
// Object[] params = {"键盘",100,"计算机配件"};
// int row = query.update(conn, sql, params); String sql = "UPDATE product SET price=? WHERE pid=?";
Object[] params = {222,11};
int row = query.update(conn, sql, params); // String sql = "DELETE FROM product WHERE pid=?";
// int row = query.update(conn, sql, 10); System.out.println(row);
//释放资源
DbUtils.closeQuietly(conn);
}
}

java JDBC (六) org.apache.commons.dbutils 增删改的更多相关文章

  1. java JDBC (七) org.apache.commons.dbutils 查询

    package cn.sasa.demo1; import java.sql.Connection; import java.sql.SQLException; import java.util.Li ...

  2. java.lang.ClassNotFoundException: org.apache.commons.dbutils.QueryRunner

    七月 28, 2017 11:06:33 下午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() fo ...

  3. 高性能jdbc封装工具 Apache Commons DbUtils 1.6(转载)

    转载自原文地址:http://gao-xianglong.iteye.com/blog/2166444 前言 关于Apache的DbUtils中间件或许了解的人并不多,大部分开发人员在生成环境中更多的 ...

  4. java.lang.ClassNotFoundException: org.apache.commons.dbutils.ResultSetHandle

    原因是这两个地方都得导入dbutils的jar包,一般出错是因为WEB-INF下没有导入包,记得导入,然后buildPath即可

  5. Java连接数据库 #04# Apache Commons DbUtils

    索引 通过一个简单的调用看整体结构 Examples 修改JAVA连接数据库#03#中的代码 DbUtils并非是什么ORM框架,只是对原始的JDBC进行了一些封装,以便我们少写一些重复代码.就“用” ...

  6. 写一个ORM框架的第一步(Apache Commons DbUtils)

    新一次的内部提升开始了,如果您想写一个框架从Apache Commons DbUtils开始学习是一种不错的选择,我们先学习应用这个小“框架”再把源代码理解,然后写一个属于自己的ORM框架不是梦. 一 ...

  7. Apache Commons DbUtils 快速上手

    原文出处:http://lavasoft.blog.51cto.com/62575/222771 Hibernate太复杂,iBatis不好用,JDBC代码太垃圾,DBUtils在简单与优美之间取得了 ...

  8. 《笔者带你剖析Apache Commons DbUtils 1.6》(转)

    前言 关于Apache的DbUtils中间件或许了解的人并不多,大部分开发人员在生成环境中更 多的是依靠Hibernate.Ibatis.Spring JDBC.JPA等大厂提供的持久层技术解决方案, ...

  9. java.lang.IllegalAccessError: org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z

    做spring和mybaits整合时出现的错误,让这个问题困扰了一早上,通过查资料终于把这个问题解决了 具体问题描述: java.lang.IllegalAccessError: org.apache ...

随机推荐

  1. Odoo小数精度及货币精度详解

    一.小数精度的设置 一般在设置-数据结构-精度设置中就可以对 小数类型的字段进行精度设置: 对于代码中定义为 digits=dp.get_precision('Product Price') 或 di ...

  2. Paypal Rest Api自定义物流地址(跳过填写物流地址)

    PayPal之前的Rest Api是不支持自定义物流地址的,最新升级版本的提供了这个服务(Payment Experience),大概步骤如下: 1.申请一个自定义的配置ID 自定义配置包括Logo, ...

  3. 数据中心内负载均衡-ECMP的使用分析

    背景 数据中心的网络拓扑通常采用CLOS结构,主机之间常存在多条路径.数据中心为满足吞吐量敏感型流量的需求会提供大量的带宽资源.那么利用数据中心这种网络拓扑已知,路径资源.带宽资源丰富的特性,可以更好 ...

  4. 基金 、 社保和QFII等机构的重仓股排名评测

    来源:基金前20大重仓股持仓股排名 基金前15大重仓股持仓股排名 基金重仓前15大个股,相较于同期沪深300的平均收益, 近1月:2.23%, 近3月:3.09%, 近6月:9.61%, 近1年:13 ...

  5. [Converge] Training Neural Networks

    CS231n Winter 2016: Lecture 5: Neural Networks Part 2 CS231n Winter 2016: Lecture 6: Neural Networks ...

  6. hashcode、equals和 ==详解

    两个对象值相同(x.equals(y) == true),则一定有相同的hash code: 这是java语言的定义: 因为:Hash,一般翻译做“散列”,也有直接音译为"哈希"的 ...

  7. 【python】用python生成pdf文件

    转自:https://www.davidfischer.name/2015/08/generating-pdfs-with-and-without-python/ from reportlab.pla ...

  8. Git详解之一 Git实战

    Git详解之一 Git实战 入门 本章介绍开始使用 Git 前的相关知识.我们会先了解一些版本控制工具的历史背景,然后试着让 Git 在你的系统上跑起来,直到最后配置好,可以正常开始开发工作.读完本章 ...

  9. SQL Server 端口号的使用

    SQL Server 端口号的使用 服务器地址  逗号 端口号 服务器地址,端口号 xxx.xxx.xxx.xxx,0000 www.xxx.com,1533  (1533是SQL Server 的端 ...

  10. css3整理--background-clip

    background-clip语法: background-clip : border-box || padding-box || content-box 参数取值: border-box:此值为默认 ...