123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package com.benyun.common.utils;
- import lombok.extern.slf4j.Slf4j;
- import java.io.File;
- import java.sql.*;
- @Slf4j
- public class DButil {
- public static Connection ConnectAccessFile(String dbpath) throws Exception{
- File dbFile = new File(dbpath);
- if(!dbFile.exists()){
- log.error("db数据库文件不存在,请确认路径是否正确:{}", dbpath);
- return null;
- }else{
- log.info("读取数据库文件,路径:{}", dbpath);
- }
- Connection conn = null;
- Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");//这个驱动的地址不要改
- String dbur1 = "jdbc:ucanaccess:///"+dbpath;
- conn = DriverManager.getConnection(dbur1, "","");
- log.info("数据库驱动OK");
- return conn;
- }
- public static void close(Connection con) {
- try {
- if(con!=null) con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void close(PreparedStatement ps) {
- try {
- if(ps!=null) ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void close(ResultSet rs) {
- try {
- if(rs!=null) rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
|