我认为这是SQL 2000/2005中的一个错误/问题。。。如果我的结果在DATETIME列上为null,我会得到
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;
这里的罪魁祸首是部分开始日期,它是一个DATETIME。我真的不能向tabel添加任何内容,因为我不允许更改现有的表结构,这是一个大系统。也许我可以在SQL中进行选角?我不太确定这是否绝对是一个零问题。。在我调用getDate()之前,是否可以调试/监视ResultSet并检查是否检索到任何数据?[/EIDT]
如果您的应用程序(或驱动程序)无法处理空日期,那么最简单的方法可能是使用ISNULL(字段,<空替换日期>)并在代码中检查空替换日期。这种方法使用幻数(日期)来表示null值,true。它不漂亮,但又快又直。
你不能用聚结吗?
http://msdn.microsoft.com/en-us/library/ms190349.aspx
您是从字段中选择日期时间,还是在SELECT
中动态构建它?您可能需要CAST
结果。
请参阅本文