MySQL操作类(本人自己写的)
package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
public class DBUtil { //定义连接数据库需要的
Connection ct=null;
PreparedStatement pS=null;
ResultSet rS=null;
private static String url = "jdbc:mysql://"+DBSomeType.MYSQLURL+":3306/weixin?characterEncoding=UTF-8&autoReconnect=true";
private static String driverName = "com.mysql.jdbc.Driver"; /**
* 数据库查询,本操作查询完需手动关闭连接
* @param sql
* @param params
* @return 查询结果ResultSet
*/
public ResultSet getSlect(String sql,Object ...params){
Vector rowDate=new Vector();
Vector columnDate =new Vector();
try {
ct = connectWithDB();
pS=ct.prepareStatement(sql);
for(int i = 0;i < params.length;i++){
pS.setObject(i+1, params[i]);
}
rS=pS.executeQuery();
} catch (Exception e) {
// TODO: handle exception
}finally{
return rS;
}
} /************修改数据库操作*********************/
public int update(String sql,Object ...params){
int executeUpdate_int = 0;
try {
ct = connectWithDB();
pS=ct.prepareStatement(sql);
for(int i = 0;i < params.length;i++){
pS.setObject(i+1, params[i]);
}
//执行操作
executeUpdate_int = pS.executeUpdate();
System.out.println("executeUpdate_int = "+executeUpdate_int);
} catch (Exception e) {
// TODO: handle exception
}finally{
shutDownDB();
return executeUpdate_int;
}
} /************连接数据库*********************/
private Connection connectWithDB(){
Connection connection = null;
try {
Class.forName(driverName);
connection= DriverManager.getConnection(url, DBSomeType.ROOTUSERNAME, DBSomeType.ROOTPASSWORD);
} catch (Exception e) {
// TODO: handle exception
}
return connection;
} /************关闭数据库的相关连接*********************/
public void shutDownDB(){
try
{
if(rS!=null) rS.close();
if(pS!=null) pS.close();
if(ct!=null) ct.close();
} catch (Exception e2)
{
e2.printStackTrace();
// TODO: handle exception
}
} }
MySQL操作类(本人自己写的)的更多相关文章
- PHP:自己写的mysql操作类
a{ font-weight: bold; display: block; text-align: center; color: #5887bf; font-size: 22px; } .conten ...
- ecshop的Mysql操作类
摘要,这是直接摘抄的ecshop的mysql操作类:不过他这里的缓存是用的文件缓存,我们如果想直接使用,可以替换成memcache的或者redis的! <?php /** * ECSHOP MY ...
- php--->单例模式封装mysql操作类
php 单例模式封装mysql操作类 单例模式的必要条件(三私一公) 私有的成员属性--防止类外引入这个存放对象的属性 私有的构造方法--为了防止在类外使用new关键字实例化对象 私有的克隆方法--为 ...
- Angular4+NodeJs+MySQL 入门-02 MySql操作类
NodeJs操作MySQL类 此类封装了几个常用的方法:插入,更新,删除,查询,开启事务,事务提交,事务回滚等操作.有一这个类,操作MYSQL就方便多了. 批处理,存储过程等方法还没有添加,因为觉得目 ...
- MySQL操作类的封装(PHP)
<?php class mysql{ /** * 报错函数 * * @param string $error */ function err($error){ die("对不起,您的操 ...
- mysql操作类
同事今天推荐了一个mysql链接操作的类,地址 https://github.com/joshcam/PHP-MySQLi-Database-Class 大概看了一下,还是不错的,有点意思,先记录一 ...
- PHP值mysql操作类
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/6/27 * Time: 18:55 */ Class M ...
- C# MySql 操作类
/* MySql 类 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- PHP封装的一个单例模式Mysql操作类
掌握满足单例模式的必要条件----三私一公. ①私有的构造方法-为了防止在类外使用new关键字实例化对象. ②私有的成员属性-为了防止在类外引入这个存放对象的属性. ③私有的克隆方法-为了防止在类外通 ...
随机推荐
- Content has been consumed
if(response.getEntity() != null && response.getEntity().getContent() != null) { message = IO ...
- 文本换行word-wrap、word-break与white-space
本文同步至微信公众号:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401671055&idx=1&sn=b88c9 ...
- mac下开发IOS代码管理
1.安装和配置subversion服务器 在windows 服务器上安装VisualSVN-Server,下载地址http://www.visualsvn.com/server/download/.采 ...
- 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- Acadia Lab 6 轮盘游戏机
WRTnode 肯定不是亲生的... 果断转投Acadia —.— 不是国军不给力,奈何共军有高达 为啥不转树莓派?因为选做实验肯定有很多人用树莓派做...我抢不过他们,只能挑点冷门的蹭分_(:з」 ...
- Math DayTwo
(1)Excel Sheet Column Number 解题思路:将26进制的数转化为10进制 代码如下: public class Solution { public int titleToNum ...
- Net 通用权限管理系统源码 带数据库设计文档,部署说明文档
Net 通用权限管理系统源码 带数据库设计文档,部署说明文档 包括数据库设计文档部署安装文档源码数据库文件 下载地址:http://www.mallhd.com/archives/1389
- 如何把apdu[decode_len]打印出来
memcpy(data, &apdu[decode_len], apdu_len - decode_len); int i = 0; for(i=0;i<apdu_len;i ...
- 常用的PHP框架
ThinkPHP http://www.thinkphp.cn Yii http://www.yiichina.com laravel https://laravel ...
- JSON 的应用
使用 JSON 需要的 jar 包: