Update data in Access DB using Java

To update data in an Access database using Java, you can use the JDBC-ODBC Bridge driver. However, please note that the JDBC-ODBC Bridge driver has been deprecated since Java 8 and is not recommended for use in production environments. It is recommended to use a dedicated JDBC driver provided by the database vendor for better performance and stability.

That being said, here’s an example using the JDBC-ODBC Bridge driver to update data in an Access database:

import java.sql.*;

public class AccessDBDataUpdater {
    public static void main(String[] args) {
        // Database URL
        String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=/path/to/your/access_database.accdb";

        // SQL query
        String query = "UPDATE your_table SET email = ? WHERE name = ?";

        try {
            // Register JDBC driver
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            // Open a connection
            Connection conn = DriverManager.getConnection(url);

            // Create a prepared statement
            PreparedStatement stmt = conn.prepareStatement(query);

            // Set parameter values
            stmt.setString(1, "[email protected]");
            stmt.setString(2, "John Doe");

            // Execute the query
            int rowsAffected = stmt.executeUpdate();

            // Process the result
            System.out.println(rowsAffected + " row(s) updated successfully.");

            // Close the resources
            stmt.close();
            conn.close();

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Replace /path/to/your/access_database.accdb with the actual path to your Access database file.

Keep in mind that the JDBC-ODBC Bridge driver might not be available in all Java environments, and its usage is discouraged in favor of native drivers provided by the database vendors.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech