在運行下面的代碼自定義數據庫表設計使用Java和MS Access
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:[微軟] [ODBC Microsoft Access驅動程序]不能修改'COFFEES'表的設計。它位於只讀數據庫中。
請幫助
我沒有創建數據庫 – user1234 2011-12-17 06:24:02
我有比OP略有不同的說法。我的聲明是「DROP TABLE MyTest」。 Access未安裝在服務器上,因此打開GUI不是一個選項。 – 2016-06-02 20:18:22