将JDBC驱动程序连接到MSSQL数据库的问题

时间:2015-08-25 19:47:19

标签: java sql eclipse jdbc jboss7.x

我们有一个java Web应用程序,我遇到了一些JDBC问题。去年,在Java 7上,使用sqljdbc4.jar连接到同一网络上另一台服务器上的SQL数据库没有问题。今年我们将应用程序升级到Java 8,这就是问题出现的时候。我们将JDBC版本更新为4.2(sqljdbc42.jar)。 .jar文件包含在我们的构建路径中,这在一年前就可以使用了。我们在Eclipse-Luna IDE中使用JBOSS 7.0。

现在当我们尝试使用JDBC时,我们得到了一个java.lang.ClassNotFoundException。

Connection conn = null;
String db_hostname = "test.fake.com";
String db_portNumber = "1433";
String db_name = "db";
String db_userid = "user";
String db_password = "password";
String db_final_string = "jdbc:sqlserver://" + db_hostname + ":" + db_portNumber + ";databaseName=" + db_name;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(_db_final_string, _db_userid, _db_password);

这是我们因Class.forName()而得到的错误:

15:30:12,919 ERROR [stderr] (http--0.0.0.0-9091-5) java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver from [Module "deployment.irw-ear.ear:main" from Service Module Loader]

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.Class.forName0(Native Method)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.Class.forName(Unknown Source)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.irw.delegate.IAContentDelegate.getIADataFromClient(IAContentDelegate.java:1776)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.irw.delegate.IAContentDelegate.getIAData(IAContentDelegate.java:1751)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.irw.ejb.IAContentBean.getIAData(IAContentBean.java:188)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

15:30:12,920 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.reflect.Method.invoke(Unknown Source)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:370)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.irw.ejb.BaseBean.intercept(BaseBean.java:27)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.reflect.Method.invoke(Unknown Source)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:67)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:370)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.irw.ejb.BaseBean.intercept(BaseBean.java:27)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)

15:30:12,921 ERROR [stderr] (http--0.0.0.0-9091-5)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.reflect.Method.invoke(Unknown Source)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:67)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:45)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:44)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

15:30:12,922 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ViewDescription$ComponentDispatcherInterceptor.processInvocation(ViewDescription.java:202)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:50)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor$CustomSessionInvocationContext.proceed(SessionInvocationContextInterceptor.java:126)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:211)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:284)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:182)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor.processInvocation(SessionInvocationContextInterceptor.java:71)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,923 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:146)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:76)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.api.IIAContent$$$view10.getIAData(Unknown Source)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.IAContentView.getIADataDubois(IAContentView.java:123)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.IAContentView.insertExternalData(IAContentView.java:98)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.IAContentView.doPost(IAContentView.java:62)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

15:30:12,924 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.filter.IRWFilter.filterRequest(IRWFilter.java:176)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at com.softified.ithos.irw.filter.IRWFilter.doFilter(IRWFilter.java:97)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)

15:30:12,925 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)

15:30:12,926 ERROR [stderr] (http--0.0.0.0-9091-5)  at java.lang.Thread.run(Unknown Source)

如果有人能提供有关如何正确配置这些最有帮助的任何见解,因为我们已经尝试了几种调整组合。

3 个答案:

答案 0 :(得分:2)

JBoss AS 7与Java 8不兼容*您需要更新到WildFly 8/9

备注

*在AS 7 on Java 8中查看更多内容。

答案 1 :(得分:0)

您必须下载兼容的Microsoft JDBC Driver for SQL Server驱动程序。你可以在msdn驱动程序中找到它。

https://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx

此网址应该可以使用。

答案 2 :(得分:0)

我明白了。我需要将jdbc驱动程序作为JBoss模块,并将其作为全局模块包含在standalone.xml中。