Java implements the operation of connecting to access database and reading data
The specific steps are as follows:
1. Connect to the access database
Create the AccessDbUtil class and connect to the database
import java.sql.Connection; import java.sql.DriverManager; /** * 获取Access连接 * * @author dofun * */ public class AccessDbUtil { public static Connection getDbConnection() { // 数据库url String url = "jdbc:Access:///E:ICD10.mdb"; Connection conn = null; try { // 驱动加载 Class.forName("com.hxtt.sql.access.AccessDriver").newInstance(); conn = DriverManager.getConnection(url); return conn; } catch (Exception e) { System.out.println("Access连接失败"); } return conn; } }
2. Read Access data and save it in the mysql database
1. Obtain the access database connection
2. Query the table data and save it
3. Close the connection resource
/** * 同步疾病,手术 * * @return */ @RequestMapping(value = "importJbbm") @ResponseBody public String importJbbm() { // 获取数据库连接 Connection conn = AccessDbUtil.getDbConnection(); PreparedStatement pst = null; ResultSet rs = null; Boolean a = true; int id = 30000; try { for (int i = 1; i > 0; i++) { // 手术 pst = conn.prepareStatement("select * from sJBBMML where id > " + id + " and LB = 'S' "); List<IcdSsbm> jbs = new ArrayList<>(); rs = pst.executeQuery(); while (a == rs.next()) { if (StringUtils.isNotBlank(rs.getString(2))) { IcdSsbm jb = new IcdSsbm(); jb.setCode(rs.getString(2)); jb.setName(rs.getString(5)); jb.setType(rs.getString(11)); jbs.add(jb); } else { a = false; i = 0; } // System.out.println(rs.getString(2)); // System.out.println(rs.getString(5)); // System.out.println(rs.getString(11)); } if (ListUtils.isNotEmpty(jbs)) { // 批量保存 icdSsbmService.saveBatch(jbs); } id += 1000; } } catch (SQLException e) { } finally { try { // 关闭资源 rs.close(); pst.close(); conn.close(); } catch (SQLException e) { } } return "导入完成"; }
Question:
If the Access database has a password set, and the password parameter is added when obtaining the connection, an error still occurs, and the reason cannot be found, so the Access database password is finally removed.
The paging problem of Access is that only 1,000 pieces of data can be queried at a time. In fact, Access itself has paging query, but it seems very cumbersome and I have no use for it, and the performance is not very good when the amount of data is large. good. So I adopt the form of loop, which is simple.
Access_JDBC30.jar is used, but java1.8 does not support Access. There seems to be a cracked driver on the Internet, which is said to break the limitation of paging query.
Recommended tutorial: access database tutorial
The above is the detailed content of Java implements the operation of connecting to access database and reading data. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Apache server is a powerful web server software that acts as a bridge between browsers and website servers. 1. It handles HTTP requests and returns web page content based on requests; 2. Modular design allows extended functions, such as support for SSL encryption and dynamic web pages; 3. Configuration files (such as virtual host configurations) need to be carefully set to avoid security vulnerabilities, and optimize performance parameters, such as thread count and timeout time, in order to build high-performance and secure web applications.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

Nginx performance monitoring and troubleshooting are mainly carried out through the following steps: 1. Use nginx-V to view version information, and enable the stub_status module to monitor the number of active connections, requests and cache hit rate; 2. Use top command to monitor system resource occupation, iostat and vmstat monitor disk I/O and memory usage respectively; 3. Use tcpdump to capture packets to analyze network traffic and troubleshoot network connection problems; 4. Properly configure the number of worker processes to avoid insufficient concurrent processing capabilities or excessive process context switching overhead; 5. Correctly configure Nginx cache to avoid improper cache size settings; 6. By analyzing Nginx logs, such as using awk and grep commands or ELK
