MS access 数据库中的插入记录
Posted
技术标签:
【中文标题】MS access 数据库中的插入记录【英文标题】:insertion records in MS access database 【发布时间】:2017-01-29 14:28:13 【问题描述】:我正在尝试在我的倒排索引中插入大量记录,该索引已在 MS access 数据库中构建为表。这是表设计(ID,term,doc,sent 是复合主键):
这是代码:
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://myDB.accdb");
Statement s = conn.createStatement();
s.execute("DELETE FROM invertedIndex");
for(String o : POSoutputs) //while (Tokenizer.hasMoreTokens())
String word = o;
s.execute("insert into invertedIndex (term,doc,sent) values ('"+ o + "','" + listOfFiles[i].getAbsolutePath() + "','" + fileText + "')");
conn.commit();// i do commit to empty the stack because i will insert thousands of records, by scanning hundreds of documents.
这是错误:
java.lang.***Error
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:297)
at java.nio.ByteBuffer.put(ByteBuffer.java:832)
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:379)
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:342)
at sun.nio.ch.IOUtil.write(IOUtil.java:60)
at sun.nio.ch.FileChannelImpl.writeInternal(FileChannelImpl.java:778)
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:761)
at com.healthmarketscience.jackcess.impl.PageChannel.allocateNewPage(PageChannel.java:350)
at com.healthmarketscience.jackcess.impl.TempPageHolder.setNewPage(TempPageHolder.java:115)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.createNewUsageMapPage(UsageMap.java:763)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.addOrRemovePageNumber(UsageMap.java:747)
at com.healthmarketscience.jackcess.impl.UsageMap.removePageNumber(UsageMap.java:337)
at com.healthmarketscience.jackcess.impl.PageChannel.allocateNewPage(PageChannel.java:354)
at com.healthmarketscience.jackcess.impl.TempPageHolder.setNewPage(TempPageHolder.java:115)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.createNewUsageMapPage(UsageMap.java:763)
at com.healthmarketscience.jackcess.impl.UsageMap$ReferenceHandler.addOrRemovePageNumber(UsageMap.java:747)
at com.healthmarketscience.jackcess.impl.UsageMap.removePageNumber(UsageMap.java:337)
at com.healthmarketscience.jackcess.impl.PageChannel.allocateNewPage(PageChannel.java:354)
at com.healthmarketscience.jackcess.impl.TempPageHolder.setNewPage(TempPageHolder.java:115)
........ ERROR RECORDS ARE DUPLICATED .. etc
有什么问题?
【问题讨论】:
【参考方案1】:错误很明显:错误记录重复
因此,您在一个或多个字段上有一个唯一索引。要么删除它,要么删除具有重复字段值的记录。
【讨论】:
我有复合主键!在所有领域!有问题吗!? 他们是!,即使只是 ID 也许真正的错误是 ***Error。如果是这样,你必须尝试另一种方法或至少更小的循环。【参考方案2】:数据库已损坏,我创建了另一个具有相同表的数据库.. 我认为原因是因为在这个问题中回答的查询:How to restart counting from 1 after erasing table in MS Access?,它损坏了数据库的结构索引。 类似的问题在:deleting row with BigIndex UsageMap exception
【讨论】:
以上是关于MS access 数据库中的插入记录的主要内容,如果未能解决你的问题,请参考以下文章
使用 C# windows 窗体向 Ms Access 数据库插入新记录时出现语法错误