jsp连接Access实现对Access的增删改查实例源码
下载地址:http://down.0379zd.com/news/show/15002.htm
package dao;
/*数据库连接基类*/
import java.sql.*;
import java.util.List;
public class BaseDao {
protected Connection conn = null;
protected ResultSet rs = null;
protected PreparedStatement pstmt =null;
//驱动路径
private final String drive ="sun.jdbc.odbc.JdbcOdbcDriver";
//url
private static String url ="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=";
//得到服务器端的url
public static void getRealPath(String realPath){
url=url+realPath;
}
/**
* 得到连接对象
* @param realPath 在服务器端数据库的真是路径
* @return 连接对象
*/
protected Connection getConn (){
try {
Class.forName(drive);
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
/**
* 关闭连接
*
*/
protected void closeAll(){
if(conn !=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 通用修改方法
* @param sql
* @param paramList
* @return 修改的结果
*/
protected int currencyUpdate(String sql,List paramList){
int result = 0;
conn = getConn();
try {
pstmt = conn.prepareStatement(sql);
result = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
/*数据库连接基类*/
import java.sql.*;
import java.util.List;
public class BaseDao {
protected Connection conn = null;
protected ResultSet rs = null;
protected PreparedStatement pstmt =null;
//驱动路径
private final String drive ="sun.jdbc.odbc.JdbcOdbcDriver";
//url
private static String url ="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=";
//得到服务器端的url
public static void getRealPath(String realPath){
url=url+realPath;
}
/**
* 得到连接对象
* @param realPath 在服务器端数据库的真是路径
* @return 连接对象
*/
protected Connection getConn (){
try {
Class.forName(drive);
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
/**
* 关闭连接
*
*/
protected void closeAll(){
if(conn !=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 通用修改方法
* @param sql
* @param paramList
* @return 修改的结果
*/
protected int currencyUpdate(String sql,List paramList){
int result = 0;
conn = getConn();
try {
pstmt = conn.prepareStatement(sql);
result = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。