使用JDBC执行SQL查询时出现异常

时间:2011-02-14 14:24:01

标签: java sql exception jdbc

我在NetBeans IDE上使用jdbc执行sql查询时遇到异常。我可以使用Microsoft SQL Server Management Studio Express执行相同的查询而没有任何错误。

以下是查询:

SELECT tcd.RouterCallKey,adc.AgentSkillTargetID,adc.AgentPeripheralNumber,adc.InstrumentPortNumber,adc.ANI,adc.DateTime,adc.TalkTime 
FROM Termination_Call_Detail tcd 
INNER JOIN 
(
SELECT tcd1.RouterCallKey, AgentSkillTargetID,AgentPeripheralNumber,InstrumentPortNumber,ANI,DateTime,TalkTime
FROM Termination_Call_Detail AS tcd1 WHERE tcd1.AgentSkillTargetID <>'' 
AND tcd1.TalkTime > 0 AND tcd1.TalkTime <=5 AND RouterCallKey <> 0 AND CallDisposition <>28
AND tcd1.DateTime >= '2011-02-03 12:00:00 AM' AND tcd1.DateTime <= '2011-02-03 11:59:59 PM'
) adc 
ON adc.RouterCallKey = tcd.RouterCallKey AND tcd.CallDisposition in (52) 
AND tcd.DateTime >= '2011-02-03 12:00:00 AM' AND tcd.DateTime <= '2011-02-03 11:59:59 PM' 
AND LEN(tcd.ANI ) > 4

以下是例外:

Incorrect syntax near the keyword 'as'

1 个答案:

答案 0 :(得分:0)

两个查询之间必须存在差异。运行SQL Server Profiler以捕获查询或执行System.out.println以显示您在Java中运行的确切查询。注意像缺少空格这样的东西:

"SELECT * FROM" +
"WHERE problem = 'No space between from and where'";