search
HomeCommon ProblemHow to correctly connect to the access database

How to correctly connect to the access database

Jan 22, 2021 am 10:43 AM
accessdatabase

How to correctly connect to the access database

Due to work needs, I need to connect to the access database. It took me a long time to sort out the correct connection steps, and now I will share them with you.

(Learning video sharing: Introduction to Programming)

1. First install JDK1.7. You cannot use JDK1.8, otherwise an exception will be reported.

2. Create an Access file with the suffix (*.mdb), create a table, the table name must be an English name, and add a field, which is also an English name.

3. Find the Control Panel under (Windows 10), find the management tools, and enter the data source (as shown in the figure below).

How to correctly connect to the access database

How to correctly connect to the access database

4. Click the fourth item to add a data source and select Access Driver.

How to correctly connect to the access database

#5. Form a binding relationship between the data source and the Access file you created.

How to correctly connect to the access database

6. Add the running code

import java. sql.*;
public class Database {
    public static void main(String[] args) {

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String url = "jdbc:odbc:Database";//Database就是刚刚添加的数据源名称
            Connection con = DriverManager.getConnection(url, "", "");//账户,密码在高级选项里,默认为空
            Statement sta = con.createStatement();
            ResultSet rst = sta.executeQuery("select * from Student");//demoTable为access数据库中的一个表名
            if (rst.next()) {
                while (rst.next()) {
                    System.out.println(rst.getString("ID"));//ID为字段名称
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

7. The running effect (the database created by each person is different, and the running effect is also different)

How to correctly connect to the access database

Related recommendations: access database tutorial

The above is the detailed content of How to correctly connect to the access database. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

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

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),