2011-02-14 91 views
1

在NetBeans IDE上使用jdbc執行sql查詢時,發生異常。我能夠使用Microsoft SQL Server Management Studio Express執行相同的查詢,沒有任何錯誤。使用JDBC執行SQL查詢時出現異常

下面是該查詢:

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'

+0

嘗試刪除`as`? – Nishant 2011-02-14 14:26:29

+0

我刪除,但仍然得到一個異常。 – AlGallaf 2011-02-14 14:34:36

回答

0

這兩個查詢之間必定存在差異。運行SQL Server Profiler來捕獲查詢或執行System.out.println以顯示您在Java中運行的確切查詢。注意像缺少空格這樣的東西:

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