【问题标题】:Custom database table design with Java and MS Access使用 Java 和 MS Access 进行自定义数据库表设计
【发布时间】:2011-12-17 06:15:44
【问题描述】:

在运行以下代码时

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”的设计。它位于只读数据库中。

请帮忙

【问题讨论】:

    标签: java sql ms-access odbc database-connection


    【解决方案1】:

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

    【讨论】:

    • 我没有创建数据库
    • 右键单击它并确保您对该文件具有写入权限。
    • 我检查了文件权限并授予 Windows 用户对数据库文件的完全控制和所有权。此外,Access 文件本身没有用户安全性。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 我在连接字符串中添加了Mode=ReadWrite;ReadOnly=false...还是不行。
      【解决方案4】:

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

      【讨论】:

      • 我没有创建数据库
      • 我的说法与 OP 略有不同。我的声明是DROP TABLE MyTest。服务器上未安装 Access,因此无法打开 GUI。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      相关资源
      最近更新 更多