我有一個簡單的程序,它使用jconnect6對一個Sybase ASE DB執行查詢。 程序迭代爲603所的記錄的結果集的while(rs.next())的NullPointerException
public ResultSet exec()
{
ResultSet rs = null;
try {
stmt= connection.createStatement();
rs = stmt.executeQuery(query);
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return rs;
}
public void Test()
{
ResultSet rs= exec();
if(rs!=null)
{
int i=0;
try {
while(rs!=null && rs.next()) { // NullPointerException here
System.out.println(i++);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
的輸出打印的值進行後拋出一個NullPointerException「I」直到其到達603而收集的記錄是超過1000和下面是誤差
May 13, 2014 11:43:43 AM appcomponents.OutageTest Test
SEVERE: null
java.lang.NullPointerException
at com.sybase.jdbc3.timedio.RawDbio.reallyRead(Unknown Source)
at com.sybase.jdbc3.timedio.Dbio.doRead(Unknown Source)
at com.sybase.jdbc3.timedio.InStreamMgr.a(Unknown Source)
at com.sybase.jdbc3.timedio.InStreamMgr.doRead(Unknown Source)
at com.sybase.jdbc3.tds.TdsProtocolContext.getChunk(Unknown Source)
at com.sybase.jdbc3.tds.PduInputFormatter.a(Unknown Source)
at com.sybase.jdbc3.tds.PduInputFormatter.read(Unknown Source)
at com.sybase.jdbc3.tds.TdsInputStream.read(Unknown Source)
at com.sybase.jdbc3.tds.TdsInputStream.readInt(Unknown Source)
at com.sybase.jdbc3.tds.TdsDataObject.readINTN(Unknown Source)
at com.sybase.jdbc3.tds.TdsInt.beginRead(Unknown Source)
at com.sybase.jdbc3.tds.TdsDataObject.doRead(Unknown Source)
at com.sybase.jdbc3.tds.TdsInt.getLong(Unknown Source)
at com.sybase.jdbc3.tds.CachedTdsInt.<init>(Unknown Source)
at com.sybase.jdbc3.tds.TdsInt.createCachedCopy(Unknown Source)
at com.sybase.jdbc3.tds.TdsResultSet.cacheCurrentRow(Unknown Source)
at com.sybase.jdbc3.tds.TdsResultSet.next(Unknown Source)
at com.sybase.jdbc3.jdbc.SybResultSet.next(Unknown Source)
at appcomponents.OutageTest.Test(OutageTest.java:143)
的ResultSet不事到處傳遞。確保連接也不是空的。我會建議你將這個resultSet合併到'void Test'方法中。 – ErrorNotFoundException
你知道在拋出npe時應該讀哪些數據嗎?你有這個hdbc驅動程序的源代碼嗎? – markusw
@Stanley,你是對的,它接近那些603記錄是在我關閉連接之前收集到的,並且NPE由於這個錯誤而被拋出。 –