易截截图软件、单文件、免安装、纯绿色、仅160KB

java无数据源连接Access数据库实例

  1.连接数据库ConnDB()类
package tool;
/****************************
**
**属性文件与数据库均在tool包下面
**
*****************************/
/* 数据访问组件 */
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class ConnDB{
private static ConnDB instance=null;
String db_driver=null;
String db_url=null;
String db_user=null;
String db_psw=null;
String db_name=null;
String proPath="conn.properties";
Connection conn=null;
public ConnDB(){
InputStream in=getClass().getResourceAsStream(proPath);
Properties prop=new Properties();
try {
prop.load(in);
db_driver=prop.getProperty("db_driver",db_driver);
db_url=prop.getProperty("db_url",db_url);
db_user=prop.getProperty("db_user",db_user);
db_psw=prop.getProperty("db_psw", db_psw);
db_name=prop.getProperty("db_name",db_name);

db_url=db_url+getDBPath();
} catch (IOException e) {
e.printStackTrace();
}
}
//获得安全连接
public synchronized Connection getConnection(){
if(instance==null){
instance=new ConnDB();
}
return instance._getConnection();
}
//释放资源
public static void dbClose(Connection conn,PreparedStatement ps,ResultSet rs){
try{
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(conn!=null){
conn.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
//创建连接
private Connection _getConnection() {
try {
Class.forName(db_driver).newInstance();
conn=DriverManager.getConnection(db_url, db_user, db_psw);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
//返回数据库的绝对路径
public String getDBPath(){
String dbpath=getClass().getResource(db_name).getFile();
dbpath=db


相关文档:

java入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

Java NIO API详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

JAVA汉字字符串按拼音排序

目标:实现一个汉字字符串按汉语拼音字典顺序排序。
原理:在windows环境的gbk字符集里,汉字是按汉语拼音字典顺序编码的,如“础”是B4A1,“储”是B4A2。这里有个问题就像上面的储和础这样的同音字只能遵照编码的顺序了,另外多音字也得遵照编码顺序。设计思路是先拆分汉字字符串为字符数组,获得每 ......

java 环境变量的配置

 1、首先安装JDK(如安装在C:\Program Files\Java\jdk1.6.0)
2、设置系统环境参数:
    1)右击“我的电脑”,选“属性”。
    2)选择“高级”选项卡,点击“环境变量”按钮
    3)点击系统变量内的“新建&rd ......

java的轻量级应用seasar+flex

Seasar2
一个项目中要用到seasar+flex,据说这个东西在小日本那里已经大量用于企业级B/S应用,当然这个开源组件也是他们开发的,所以收集一些相关资料,备忘..
所谓“Seasar2”就是一个“轻量级容器”,面向无法摆脱“Java 应用开发”之烦恼的所谓“开发者”,它能够保证开发的&ldq ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号