我試圖獲得結果的類型和名稱,並在循環中輸入時,resumeset.next從true更改爲false ,並給出錯誤java.sql.SqlExcepcion用盡的結果集。有任何想法嗎?我真的不知道如何解決它,因爲我讀這個問題的解決方案後,並驗證結果集是否爲null之前開始循環。我把這種方法稱爲石英調度器。我在J2EE aplication利用這一點,並例子正是這種用盡resultset錯誤,當我得到列的名稱
try
{
InitialContext ctx = new InitialContext();
WrapperDataSource wrapperDataSource = (WrapperDataSource)ctx.lookup(systemLogger.getConfigurationParameters().getDataSource());
conn = wrapperDataSource.getConnection();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn = DriverManager.getConnection(url,login,password);
if (conn != null)
{
stmt = conn.createStatement();
res = stmt.executeQuery(query);
if (res != null)
{
while (res.next())
{
for (int i = 0; i < columnlength; i++)
{
String columnName = metadata.getColumnName(i+1);
if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnStatus()))
{
columnStatusType = metadata.getColumnType(i+1);
}
else if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnDocumentId()))
{
columnDocumentIdType = metadata.getColumnType(i+1);
}
else if (metadata.getColumnName(i+1).equalsIgnoreCase(systemLogger.getColumnTimer()))
{
columnTimerType = metadata.getColumnType(i+1);
}
}
}
}
else
{
__log.error("No results found for the query");
throw new PtmServiceException("No se encontraron resultados para el query");
}
}
else
{
__log.error("Could not create the connection");
throw new PtmServiceException("No se pudo crear la conexion");
}
}
catch(Exception e)
{
__log.error("Error in the execution of the query");
throw new PtmServiceException("Error ejecutando la busqueda");
}
finally
{
res.close();
stmt.close();
conn.close();
}
你在哪裏捕捉這個異常?導致此異常的行在哪裏?您顯示的代碼不訪問結果集併吞下所有異常,並會產生不同的異常。 – BalusC 2010-09-29 02:16:55
嗨,感謝您提出我的問題,我正在捕捉異常行中的'columnStatusType = metadata.getColumnType(i + 1);'在for循環的第二個 – Jorge 2010-09-29 19:13:09