易截截图软件、单文件、免安装、纯绿色、仅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调用exe或者bat文件

 import java.io.*;
public class TestExe {
    public static void main(String[] args) throws InterruptedException {
 try {
   Process child = Runtime.getRuntime().exec("C://Program Files//Sunyard//ImageInput//ImageInput.exe");
   child.waitFor();
&n ......

JAVA中的Singleton模式

单例模式,顾名思义,只能有一个实例。
一.从多线程安全说起,如下图代码,此问题可以用synchronized关键字来解决。该方法缺点:每一个线程在获取实例对象之前都要在synchronized上同步的对象上进行等待,因此效率不高。
二.Double Check方法,见下图代码。Double Check的初衷是只有当instance为NULL时执行的线程才需要在 ......

在JAVA中使用拖拽功能

 在JAVA中使用拖拽功能
sun在java2中引入了一些新的方法来帮助实现拖拽功能,这些新的类在java.awt.dnd包中
实现一个D&D操作一般包括三个步骤:
 首先实现一个拖拽源,这个拖拽源和相应的组件是关联起来的
 第二步实现一个拖拽目标,这个目标用来实现拖拽物的接收
 第三步实现一个数据传输对象 ......

Java中怎样判断一个字符串是否是数字???

 在编程的时候,经常遇到要判断一个字符串中的字符是否是数字(0-9)
 下面我给大家介绍几种实现方法
1.使用Character.isDigit(char)判断
String str = "123abc";
if (!"".equals(str)) {
char num[] = str.toCharArray();//把字符串转换为字符数组
StringBuffer title = new StringBuffer();//使用S ......

JAVA汉字字符串按拼音排序

目标:实现一个汉字字符串按汉语拼音字典顺序排序。
原理:在windows环境的gbk字符集里,汉字是按汉语拼音字典顺序编码的,如“础”是B4A1,“储”是B4A2。这里有个问题就像上面的储和础这样的同音字只能遵照编码的顺序了,另外多音字也得遵照编码顺序。设计思路是先拆分汉字字符串为字符数组,获得每 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号