我需要在访问数据库中创建一个表,为此我使用了以下代码。它正在创建表,但在单击表时会引发类似“保留错误(-5001)并且没有出现此错误的原因”之类的错误。
我的代码:
public class NewClass {
public static void main (String args[])
{
String dbFileSpec = "C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\AutomateExcelDatabase\\Centre.accdb";
try (Connection conn = DriverManager.getConnection(
"jdbc:ucanaccess://" + dbFileSpec
+ ";newdatabaseversion=V2007")) {
DatabaseMetaData dmd = conn.getMetaData();
try (ResultSet rs = dmd.getTables(null, null, "Clients", new String[]{"TABLE"})) {
if (rs.next()) {
System.out.println("Table [Clients] already exists.");
} else {
System.out.println("Table [Clients] does not exist.");
try (Statement s = conn.createStatement()) {
s.executeUpdate("CREATE TABLE Clients (ID COUNTER PRIMARY KEY, LastName TEXT(100))");
System.out.println("Table [Clients] created.");
}
}
}
conn.close();
} catch (SQLException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
提出一些解决此错误的想法。