JDBCTool
新建 *.properties属性文件,内容如下:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/dbName
username=root
password=root
public class DbTool {
private static String db_driver=null;
private static String db_url=null;
private static String db_user=null;
private static String db_password=null;
public static Connection getConnection() throws ClassNotFoundException, IOException{
Connection conn=null;
InputStream in=DbTool.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties=new Properties();
properties.load(in);
db_driver=properties.getProperty("driver");
db_url=properties.getProperty("url");
db_user=properties.getProperty("user");
db_password=properties.getProperty("password");
try {
Class.forName(db_driver);
conn=DriverManager.getConnection(db_url,db_user,db_password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated catch block
// TODO Auto-generated catch block
return conn;
}
public static void close(ResultSet rs){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(PreparedStatement prst){
if(prst!=null){
try {
prst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(Connection conn){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(PreparedStatement prst,Connection conn){
close(prst);
close(conn);
}
public static void close(ResultSet rs,PreparedStatement prst,Connection conn){
close(rs);
close(prst);
close(conn);
}
}
JDBCTool的更多相关文章
- 比较满意设计的一次作业 JDBC宠物管理
package com.dao; import java.util.List; import com.entity.Master; public interface MasterDao { publi ...
- JavaFX——简单的日记系统
前言 在学习Swing后,听老师说使用Java写界面还可以使用JavaFX.课后,便去了解.JavaFX是甲骨文公司07年推出的期望应用于桌面开发领域的技术.在了解了这个技术几天后,便使用它完成Jav ...
- Java实现的并发任务处理实例
本文实例讲述了Java实现的并发任务处理方法.分享给大家供大家参考,具体如下: public void init() { super.init(); this.ioThreadPool = new T ...
- AlanShan数据库课程设计报告
目 录 1.绪论.... 2 1.1前言... 2 1.2社会背景... 2 1.3超市背景... 3 2.系统可行性研究.... 4 2.1 技术可行性研究... 4 2.2 经济可行性研究. ...
随机推荐
- GridView数据绑定控件的模版列时设置显示的格式
形式 语法 结果 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4} $12.3656 货币 "¥{0:N2}&q ...
- 手把手教你如何利用Meterpreter渗透Windows系统
在这篇文章中,我们将跟大家介绍如何使用Meterpreter来收集目标Windows系统中的信息,获取用户凭证,创建我们自己的账号,启用远程桌面,进行屏幕截图,以及获取用户键盘记录等等. 相关Payl ...
- linux下的环境文件设置说明
工作环境设置文件 环境设置文件有两种:系统环境设置文件 和 个人环境设置文件 1.系统中的用户工作环境设置文件: 登录环境设置文件:/etc/profile 非登录环境设置文件: ...
- xml文件的根节点layout_width或者layout_height设置无效果的原因分析
在android开发中相信大家对ListView.GridView等组建都非常熟悉,在使用它们的时候须要自己配置相关的Adapter,而且配置现骨干的xml文件作为ListView等组建的子View, ...
- Android 非静态内部类导致内存泄漏原因深入剖析
背景 上周发现蘑菇街IM-Android代码里面.一些地方代码编写不当.存在内存泄漏的问题.在和疯紫交流的过程中.发现加深了一些理解,所以决定写一下分析思路,相互学习. 内存泄漏 一个不会被使用的对象 ...
- python-pyDes-ECB加密-DES-DES3加密
网上的教程都他妹的是抄的,抄也就算了,还改抄错了,害我写了一两天都没找到原因,直接去官网看,找例子很方便 官网链接:http://twhiteman.netfirms.com/des.html 一个小 ...
- React_Redux_Router
一.react_redux 比较好的blog: blog1, blog2, blog3 主要根据前两个blog总结如下: 1. React在组件内部(包括子组件)为单向数据流且自上向下通过props传 ...
- multimap容器和multiset容器中的find操作
前言 multimap容器是map容器的“ 增强版 ”,它允许一个键对应多个值.对于map容器来说,find函数将会返回第一个键值匹配元素所在处的迭代器.那么对于multimap容器来说,find函数 ...
- Topcoder SRM 638 DIV 2 (大力出奇迹)
水题,就是一个暴力.大力出奇迹. Problem Statement There is a narrow passage. Inside the passage there are some wo ...
- wince c# 创建桌面快捷方式 自动启动 只运行一次 全屏显示
using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.R ...