Home Topics Access Java implements the operation of connecting to access database and reading data

Java implements the operation of connecting to access database and reading data

Nov 19, 2020 pm 03:18 PM
access java database

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

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;

    }

}

Copy after login

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

/**

     * 同步疾病,手术

     *

     * @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 "导入完成";

    }

Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

How to use Debian Apache logs to improve website performance How to use Debian Apache logs to improve website performance Apr 12, 2025 pm 11:36 PM

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

How to configure zend for apache How to configure zend for apache Apr 13, 2025 pm 12:57 PM

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 vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

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.

See all articles