簡體   English   中英

Java-Derby-JDBC-NullPointerException PreparedStatement

[英]Java - Derby - JDBC - NullPointerException PreparedStatement

我的程序有問題。

我使用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的表,該表可以正常工作,但是突然崩潰了,我不知道如何使其重新工作。

感謝您的幫助!

不幸的是,您的數據庫似乎已損壞。

您是否有可以還原的數據庫備份?

這不應該發生,並且可能表明Derby中存在錯誤。

在嘗試重現該問題之前,應保存數據庫文件夾和derby.log以及您可以收集的任何其他信息,並與derby-dev郵件列表上的開發人員聯系; 也許他們可以幫助您弄清楚數據庫是如何損壞的。

包括有關您正在使用的Derby版本,Java的版本,運行的操作系統等的所有信息。

您可以使用新的空數據庫來重現此問題嗎?

使用Squirrel添加表時,您的程序是否也在同時運行?

在數據庫損壞之前是否還有其他奇怪的事件發生? (您的程序崩潰了,您的計算機崩潰了,您的磁盤已滿,程序耗盡了內存,等等?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM