0

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

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

i didn't created the database
Do a right click on it and make sure that you have write permissions to the file.
I checked file permissions and gave the Windows user Full Control and Ownership over the database file. Additionally, there is no user security in the Access file itself.
1

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

enter image description here

Comments

1

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

1 Comment

I added Mode=ReadWrite;ReadOnly=false to the connection string... it still didn't work.
0

try deleting the table explicitly and run again.

2 Comments

i didn't created the database
I have a slightly different statement than the OP. My statement is DROP TABLE MyTest. Access is not installed on the server so opening the GUI is not an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.