camel-sql 问题(不同的 sql server 版本)
Posted
技术标签:
【中文标题】camel-sql 问题(不同的 sql server 版本)【英文标题】:camel-sql issue (different sql server versions) 【发布时间】:2020-03-03 19:49:57 【问题描述】:我有一个基本的骆驼路线(在 karaf 中运行),这条路线从 SQL 表中返回一个 ID 列表,当连接到 SQL Server 2012 时,该路线按预期工作,
路线:
private static final String GET_PRODUCTS_QUERY = "select PRODUCT_ID,PRODUCT_DESC from CO_PROD";
from("direct-vm:sqlRoute").routeId("testSQL")
.streamCaching()
.to(String.format("sql:%s?dataSource=sqlDataSource", GET_PRODUCTS_QUERY))
.log(LoggingLevel.INFO, "SQL response = $body");
blueprint.xml
<reference id="sqlDataSource" filter="(osgi.jndi.service.name=sqlDataSource)" interface="javax.sql.DataSource"/>
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="sqlDataSource"/>
</bean>
当连接到 SQL 2008(这具有相同的表/数据)时,我从同一条路径收到以下错误:
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-2BJK8S2-0119-1583263311016-6-2]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1846)
at org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:385)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:64)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.directvm.DirectVmProcessor.process(DirectVmProcessor.java:57)
at org.apache.camel.component.directvm.DirectVmBlockingProducer.process(DirectVmBlockingProducer.java:53)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.jetty.CamelContinuationServlet.doService(CamelContinuationServlet.java:215)
at org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:760)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1296)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1211)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:54)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:512)
at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:54)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:512)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:500)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:386)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:562)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:378)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/antlr/v4/runtime/ANTLRErrorListener
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:347)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3103)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3114)
at org.apache.camel.component.sql.SqlProducer$2.doInPreparedStatement(SqlProducer.java:120)
at org.apache.camel.component.sql.SqlProducer$2.doInPreparedStatement(SqlProducer.java:116)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
at org.apache.camel.component.sql.SqlProducer.process(SqlProducer.java:116)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
... 44 more
Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.ANTLRErrorListener not found by com.microsoft.sqlserver.mssql-jdbc [47]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639)
at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 52 more
如果我切换到下面的 jdbc 连接方式,它适用于 SQL Server 2008:
from("direct-vm:sqlRoute").routeId("testSQL")
.streamCaching()
.setBody(simple("select PRODUCT_ID,PRODUCT_DESC from CO_PROD",String.class))
.to("jdbc:sqldataSource")
.log(LoggingLevel.INFO, "SQL response = $body");
camel-sql 是否只适用于某些版本的 SQL 服务器?
有没有办法记录在 .to 中发送的端点/连接信息?
谁能帮我理解为什么初始路由不适用于 SQL 2008,但连接到 SQL 2012 的同一路由却可以正常工作?
【问题讨论】:
【参考方案1】:引起:java.lang.ClassNotFoundException: org.antlr.v4.runtime.ANTLRErrorListener 未找到 com.microsoft.sqlserver.mssql-jdbc
也许您需要尝试另一个 jdbc 驱动程序,例如 List of JDBC drivers for SQL Server 2008 (comparison)
【讨论】:
以上是关于camel-sql 问题(不同的 sql server 版本)的主要内容,如果未能解决你的问题,请参考以下文章
SQL serve 2008 r2安装失败,为啥?怎么办才好!!!!急急急!!!!