/**
先要创建access数据库 保存mdb格式 放在对应得目录
*
*/
package com.li72.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
/**
* 类名称:BengConDB
* 类描述:
* 创建人:li72
* 创建时间:2012-4-7 下午01:08:17
* 修改人:li72
* 修改时间:2012-4-7 下午01:08:17
* 修改备注:
*/
public class BengConDB {
private static Connection con=null;
private static Statement statement;
private static BengConDB bcon=null;
public static BengConDB getInstace(){
if(bcon==null){
bcon=new BengConDB();
}
return bcon;
}
public final String ur1="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:/qfc.mdb";
public BengConDB(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Properties prop = new Properties();
prop.put("charSet", "gbk"); //解决中文乱码
try {
con = DriverManager.getConnection(ur1,prop);
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}public static Statement getStatement() throws Exception{
statement=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
return statement;
}
public ResultSet getResultSet(String sql) throws Exception{
ResultSet rs=getStatement().executeQuery(sql);
return rs;
}
public int excuteUpdate(String sql) throws Exception{
int num=getStatement().executeUpdate(sql);
return num;
}
}
红色为解决插入中文乱码