简体   繁体   English

使用JDBC执行SQL查询时发生异常

[英]Exception while executing SQL Query using JDBC

I get an exception while executing an sql query using jdbc on NetBeans IDE. 在NetBeans IDE上使用jdbc执行sql查询时出现异常。 I'm able to execute the same query using Microsoft SQL Server Management Studio Express without any errors. 我可以使用Microsoft SQL Server Management Studio Express执行相同的查询,而不会出现任何错误。

Here is the query: 这是查询:

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

Here is the exception: 这是例外:

Incorrect syntax near the keyword 'as' . Incorrect syntax near the keyword 'as'

There must be a difference between the two queries. 两个查询之间必须有区别。 Run the SQL Server Profiler to capture the query or do a System.out.println to display the exact query you are running in Java. 运行SQL Server Profiler捕获查询,或执行System.out.println以显示您在Java中运行的确切查询。 Look out for things like missing spaces like so: 注意诸如缺少空格之类的东西:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM