2011-05-24 73 views
0

我相信這已經在SQL 2000/2005的錯誤/問題...如果我的成績有空的DATETIME列,我得到轉換是空日期不支持

com.microsoft.sqlserver.jdbc.sqlserverexception: 
the conversion from int to date is unsupported 

當我使用sql.getDate("ColumnName") ... 任何解決方案?下面

[編輯] 大家好感謝您的投入,是我的SQL查詢

select p.planno   as PlanNumber, 
     t.TrancheID   as TrancheID, 
     t.tranchestartdate as TrancheStartDate, 
     t.tranchereasoncode as TrancheReasonCode, 
     ai.ArrayItemDecode TrancheReasonDescription, 
     t.trancheuwstage as UnderwritingStatusCode 
from plan_ p 
     inner join tranche t 
     on t.planno = p.planno 
      and t.trancheuwstage in (2, 4) 
      and p.planno = '040000000X6' 
     inner join arrayitem ai 
     on ai.ArrayNm = 'arrTraReas' 
      and ai.ArrayItemCode = t.tranchereasoncode; 

,這裏的罪魁禍首是tranchestartdate這是一個DATETIME。我無法真正添加任何tabel,因爲我不允許更改現有的表結構,這是一個很大的系統。也許我可以在我的SQL中進行投射?我不太確定這是否肯定是空的問題..可以通過ResultSet調試/監視並檢查是否有任何數據在我調用getDate()之前檢索? [/ EIDT]

+0

沒有'null'日期? – Oded 2011-05-24 09:43:34

+0

JDBC認爲該列是int必須有一個原因。你確定SQL字段不是TIMESTAMP數據類型嗎? – 2011-05-24 09:46:07

+2

@詹姆斯。沒有任何轉換的'NULL'文字被SQL Server視爲'int',但'int'確實轉換爲'datetime'。 'SELECT CAST(0 AS DATETIME)'賦予'1900-01-01 00:00:00.000'和'SELECT CAST(CAST(NULL AS INT)AS DATETIME)''NULL' – 2011-05-24 09:50:17

回答

0

如果您的應用程序(或驅動程序)不能處理空日期那麼最簡單的事情可能是使用ISNULL(場,<空更換日期>),並檢查代碼中的空更換日期。這種方法使用幻數(日期)來表示空值,true。這不太好,但它很快捷。

0

您是從字段中選擇日期時間還是在您的SELECT中動態構建日期時間?你可能不得不CAST的結果。

請參閱this article

+0

嗨,請檢查我的問題,因爲我已編輯它.... – sonx 2011-05-24 11:17:57