| | |
| | | **/ |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.Socket; |
| | | import java.net.SocketAddress; |
| | | import java.sql.*; |
| | | |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class ReadAccessDatabase { |
| | | |
| | | public static void main(String[] args) { |
| | | // 多个数据库文件路径 |
| | | String[] dbPaths = { |
| | | "D:\\Workspaces\\ard\\安瑞达工作资料\\mdb\\道路中心线.mdb" |
| | | // "D:\\Workspaces\\ard\\安瑞达工作资料\\mdb\\防风林-灌木.mdb", |
| | | // 添加更多的数据库文件路径 |
| | | }; |
| | | Boolean aBoolean = IsConnectTcpServer("127.0.0.1", 1200, 100); |
| | | String message = aBoolean ? "success" : "fail"; |
| | | log.info(message); |
| | | |
| | | // 遍历每个数据库文件 |
| | | for (String dbPath : dbPaths) { |
| | | readDataFromAccessDatabase(dbPath); |
| | | } |
| | | // 多个数据库文件路径 |
| | | // String[] dbPaths = { |
| | | // "D:\\Workspaces\\ard\\安瑞达工作资料\\mdb\\道路中心线.mdb" |
| | | //// "D:\\Workspaces\\ard\\安瑞达工作资料\\mdb\\防风林-灌木.mdb", |
| | | // // 添加更多的数据库文件路径 |
| | | // }; |
| | | // |
| | | // // 遍历每个数据库文件 |
| | | // for (String dbPath : dbPaths) { |
| | | // readDataFromAccessDatabase(dbPath); |
| | | // } |
| | | } |
| | | |
| | | public static void readDataFromAccessDatabase(String dbPath) { |
| | |
| | | // 可以根据具体的表结构继续获取其他字段的数据 |
| | | |
| | | // 在这里处理获取到的数据,例如输出到控制台或保存到集合中 |
| | | log.info("ID: " + id + ", No: " + no+ ", Name: " + name); |
| | | log.info("ID: " + id + ", No: " + no + ", Name: " + name); |
| | | } |
| | | // 关闭连接 |
| | | resultSet.close(); |
| | |
| | | } |
| | | } |
| | | |
| | | public static Boolean IsConnectTcpServer(String ip,Integer port,Integer timeOut) { |
| | | try { |
| | | Socket socket = new Socket(); |
| | | socket.connect(new InetSocketAddress(ip, port), timeOut); |
| | | socket.close(); |
| | | return true; |
| | | } catch (IOException e) { |
| | | // log.error(e.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |