我的程序出了问题。
我使用Derby数据库并在其上连接JDBC。但每当我调用一个与数据库“做某事”的函数时,我都会得到一个nullpointerexception。
所以这是例外:
java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at notetool.database.Database_Manager.getCatDirs(Database_Manager.java:161)
at Notetool.<init>(Notetool.java:30)
at Notetool.main(Notetool.java:23)
Caused by: java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 17 more
Caused by: java.lang.NullPointerException
at org.apache.derby.iapi.types.TypeId.getTypeId(Unknown Source)
at org.apache.derby.iapi.types.DataTypeDescriptor.getType(Unknown Source)
at org.apache.derby.impl.sql.catalog.SYSCOLUMNSRowFactory.buildDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndexMinion(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndex(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.finishTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptorIndex1Scan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getUncachedTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.NameTDCacheable.setIdentity(Unknown Source)
at org.apache.derby.impl.services.cache.ConcurrentCache.find(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 10 more
第161行是:
PreparedStatement statement = con.prepareStatement("SELECT name FROM dir");
完整的功能:
public ArrayList<String> getCatDirs() {
con = initConnection();
ArrayList<String> dirs = new ArrayList<String>();
ResultSet resultSet;
try {
PreparedStatement statement = con.prepareStatement("SELECT name FROM dir");
resultSet = statement.executeQuery();
int columnCnt = resultSet.getMetaData().getColumnCount();
while (resultSet.next()) {
for(int i = 1; i <= columnCnt;i++){
dirs.add(resultSet.getString(i) + " ");
}
}
resultSet = statement.executeQuery("SELECT MAX(dirid) FROM dir");
columnCnt = resultSet.getMetaData().getColumnCount();
while( resultSet.next()) {
setCatIds(resultSet.getInt(columnCnt));
}
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dirs;
}
这里也是initConnection()函数
public Connection initConnection() {
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con = DriverManager.getConnection("jdbc:derby:db/notedb;create=true;user=admin;password=1234;schema=admin");
} catch (SQLException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
我真的不知道这个问题是什么。大约一小时前它运行良好。
也许这有帮助,它是derby.log的输出
------------ BEGIN SHUTDOWN ERROR STACK -------------
ERROR XSDB0: Unexpected exception on in-memory page Page(5,Container(0, 144))
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.store.raw.data.StoredPage.initSlotTable(Unknown Source)
at org.apache.derby.impl.store.raw.data.StoredPage.initFromData(Unknown Source)
at org.apache.derby.impl.store.raw.data.CachedPage.setIdentity(Unknown Source)
at org.apache.derby.impl.services.cache.ConcurrentCache.find(Unknown Source)
at org.apache.derby.impl.store.raw.data.FileContainer.getUserPage(Unknown Source)
at org.apache.derby.impl.store.raw.data.FileContainer.getPage(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown Source)
at org.apache.derby.impl.store.access.conglomerate.OpenConglomerate.latchPage(Unknown Source)
at org.apache.derby.impl.store.access.conglomerate.GenericConglomerateController.fetch(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndexMinion(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndex(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.finishTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptorIndex1Scan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getUncachedTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.NameTDCacheable.setIdentity(Unknown Source)
at org.apache.derby.impl.services.cache.ConcurrentCache.find(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at notetool.database.Database_Manager.getCatDirs(Database_Manager.java:161)
at Notetool.<init>(Notetool.java:30)
at Notetool.main(Notetool.java:23)
------------ END SHUTDOWN ERROR STACK -------------
Fri Jan 03 23:19:42 CET 2014 Thread[main,5,main] (XID = 1389), (SESSIONID = 1), (DATABASE = db/notedb), (DRDAID = null), Cleanup action starting
Fri Jan 03 23:19:42 CET 2014 Thread[main,5,main] (XID = 1389), (SESSIONID = 1), (DATABASE = db/notedb), (DRDAID = null), Failed Statement is: SELECT name FROM dir
java.lang.NullPointerException
at org.apache.derby.iapi.types.TypeId.getTypeId(Unknown Source)
at org.apache.derby.iapi.types.DataTypeDescriptor.getType(Unknown Source)
at org.apache.derby.impl.sql.catalog.SYSCOLUMNSRowFactory.buildDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndexMinion(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getDescriptorViaIndex(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getColumnDescriptorsScan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.finishTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptorIndex1Scan(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getUncachedTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.catalog.NameTDCacheable.setIdentity(Unknown Source)
at org.apache.derby.impl.services.cache.ConcurrentCache.find(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.getTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at notetool.database.Database_Manager.getCatDirs(Database_Manager.java:161)
at Notetool.<init>(Notetool.java:30)
at Notetool.main(Notetool.java:23)
Cleanup action completed
正如已经说过的,大约两个小时前它运行良好。我在数据库中添加了一个带有SquirrelSQL的表,这有什么用,但突然之间崩溃了,我不知道如何让它再次运行。
感谢您的帮助!
答案 0 :(得分:0)
不幸的是,您的数据库看起来已经腐败了。
您是否有可以从中恢复的数据库备份?
这不应该发生,并且可能表明Derby中存在错误。
在尝试重现问题之前,您应该保存数据库文件夹和derby.log以及可以收集的任何其他信息,并与derby-dev邮件列表上的开发人员联系;也许他们可以帮助你弄清楚数据库是如何腐败的。
包含有关您正在使用的Derby版本,Java版本,运行的操作系统等的任何信息。
您可以使用新的空数据库重现此问题吗?
当您使用Squirrel添加表时,您的程序是否同时运行?
在数据库损坏之前发生了其他奇怪事件吗? (你的程序崩溃,机器崩溃,你的磁盘已满,你的程序内存不足等等?)