我正在使用以下数据源连接到 MS SQL 服务器
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" >
<property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:jtds:sqlserver://<server>:<port>" />
<property name="user" value="${echo_db_user}" />
<property name="password" value="${echo_db_password}" />
</bean>
<bean id="myProviderDAO" class="com.care.dao.impl.DataProviderImpl">
<property name="dataSource" ref="myDataSource" />
</bean>
public class DataProviderImpl extends JdbcDaoSupport{
public Object runQuery(String staticQuery) {
try {
return getJdbcTemplate().queryForList(staticQuery);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
静态查询是:
Select
sender,
status_dt
FROM
ServiceTickets.dbo.trouble_ticket
WHERE
status_dt BETWEEN '02-17-2010 07:00:00' AND '04-30-2014 05:00:00'
运行此查询时,我收到以下异常:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [
Select
sender,
status_dt
FROM
ServiceTickets.dbo.trouble_ticket
WHERE
status_dt BETWEEN '02-17-2010 07:00:00' AND '04-30-2014 05:00:00'
]; nested exception is java.sql.SQLException: ORA-00933: SQL command not properly ended
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
- 连接正在发生,因为我已经调试了代码并且它通过了检索连接的位置。
- 如果我在 Toad(ms sql 服务器的客户端)上执行相同的查询,则可以正确执行。
- 我使用相同的步骤连接到 Qracle DB 并执行它的查询,它工作正常,只有在 MS SQL 服务器的情况下我面临这个问题。