使用 Java 和 MS Access 进行自定义数据库表设计

发布于 2024-12-22 00:35:44 字数 1447 浏览 0 评论 0原文

运行以下代码时,

public class Temp {

    public static void main(String args[]) {

        Connection con; // The connection to the database.
        // The following code can throw errors, so they must be caught.
        try{

            // First, tell Java what driver to use and where to find it.
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            // Next, create a connection to your data source.
            // Specify that you are using the ODBC-JDBC Bridge.
            // And specify the data source from ODBC.
            con = DriverManager.getConnection("jdbc:odbc:Temp");
            // Create an SQL statement.
            Statement stmt = con.createStatement();
            // Execute some SQL to create a table in your database.
            // If the table already exists, an exception is thrown!
            stmt.executeUpdate("CREATE TABLE COFFEES " +
            "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
            "SALES INTEGER, TOTAL INTEGER)");

        }
        // Catch any exceptions that are thrown.
        catch(ClassNotFoundException e){

            System.out.println(e.toString());

        }
        catch(SQLException e){

            System.out.println(e.toString());

        }

    }

}

我收到错误如下

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 无法修改表“COFFEES”的设计。它位于只读数据库中。

请帮忙

While running the following code

public class Temp {

    public static void main(String args[]) {

        Connection con; // The connection to the database.
        // The following code can throw errors, so they must be caught.
        try{

            // First, tell Java what driver to use and where to find it.
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            // Next, create a connection to your data source.
            // Specify that you are using the ODBC-JDBC Bridge.
            // And specify the data source from ODBC.
            con = DriverManager.getConnection("jdbc:odbc:Temp");
            // Create an SQL statement.
            Statement stmt = con.createStatement();
            // Execute some SQL to create a table in your database.
            // If the table already exists, an exception is thrown!
            stmt.executeUpdate("CREATE TABLE COFFEES " +
            "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
            "SALES INTEGER, TOTAL INTEGER)");

        }
        // Catch any exceptions that are thrown.
        catch(ClassNotFoundException e){

            System.out.println(e.toString());

        }
        catch(SQLException e){

            System.out.println(e.toString());

        }

    }

}

i got the error as

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Cannot modify the design of table 'COFFEES'. It is in a read-only database.

please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月蹉跎了容颜 2024-12-29 00:35:44

确保您当前用户具有对数据库/文件的写访问权限。

Make sure that you have write access to the database/file with your current user.

只是偏爱你 2024-12-29 00:35:44

检查 ODBC DSN 中的高级选项并确保 ReadOnly 设置为 0

在此处输入图像描述

Check the advanced options in the ODBC DSN and make sure ReadOnly is set to 0.

enter image description here

岛徒 2024-12-29 00:35:44

您需要将 "ReadOnly=False;" 添加到连接字符串中

You need to add "ReadOnly=False;" to your connection string

分开我的手 2024-12-29 00:35:44

尝试显式删除该表并再次运行。

try deleting the table explicitly and run again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文