Java Spring JDBC SQL Server连接错误

梅尔

尝试使用jdbc将Tomcat上的Java Spring应用程序连接到sqlserver数据库。出现错误:

“请求处理失败;嵌套异常是org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取JDBC连接;嵌套异常是org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(与主机BEN-790的连接,命名实例sqlexpress失败。错误:“ java.net.SocketTimeoutException:接收超时”。验证服务器和实例名称,并检查是否没有防火墙阻止UDP通讯访问端口1434。对于SQL Server 2005或更高版本,请验证SQL Server Browser服务在主机上运行。)”

pom.xml

<!-- Server Connection -->

-<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>

<!-- Test -->
-<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>


-<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.FINAL</version>
</dependency>

-<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>

<version>1.3.1</version>
</dependency>

-<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>runtime</scope>
</dependency>

</dependencies>
-<build>
-<plugins>
-<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
-<configuration>
-<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>

-<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>

<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>

</plugin>
-<plugin>
<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
-<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>

</plugin>

-<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
+<configuration>
</plugin>

-<plugin>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</plugin>
</plugins>

我的servlet-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
-<beans:beans xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" xmlns:context="http://www.springframework.org/schema/context" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/mvc">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven/>

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->

<resources location="/resources/" mapping="/resources/**"/>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

-<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property value="/WEB-INF/views/" name="prefix"/>
<beans:property value=".jsp" name="suffix"/>
</beans:bean>

<!-- Enables us to use message.properties files -->
-<beans:bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
<beans:property value="home" name="basename"/>
</beans:bean>

<!-- Enable connection to MS SQL -->
-<beans:bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
<beans:property value="com.microsoft.sqlserver.jdbc.SQLServerDriver" name="driverClassName"/>
<!-- <beans:property name="url" value="jdbc:jtds:sqlserver://localhost/bens;instance=sqlexpress;useNTLMv2=true;domain=BEN-790"/> -->

<beans:property value="jdbc:sqlserver://BENS-790\SQLEXPRESS;databaseName=TIGGER" name="url"/>
<beans:property value="COMPANY\bens" name="username"/>
<beans:property value="" name="password"/>
</beans:bean>

<!-- <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <beans:property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/> <beans:property name="url" value="jdbc:sqlserver://COL-INFA:1433;databaseName=bens"/> <beans:property name="username" value="bens"/> <beans:property name="password" value="MyPwd"/> </beans:bean> -->

<context:component-scan base-package="com.company.tigger"/>

</beans:beans>
jpganz18

为此,如何更改连接bean?

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
        <!-- S2-Install-Start: INSERT DB SERVER HERE -->
        <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=MyDatabase;" />
        S2-Install-End:
        <property name="username" value="Stefana\Steffi" />
        S2-Install-Start: INSERT DB PASSWORD HERE
        <property name="password" value="" />
        S2-Install-End:
    </bean>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring JDBC错误连接

无法使用 Spring JDBC 通过 SSL 连接到 SQL Server

来自Java jdbc连接的架构名称Sql Server

JDBC Spring中的错误SQL语法异常

Spring JDBC中的错误SQL语法异常

错误:org.springframework.jdbc.BadSqlGrammarException:StatementCallback; 错误的SQL语法Java Spring MVC

JSP项目中的JDBC SQL Server连接错误

JDBC,连接到SQL Server

Java 8上的SQL Server JDBC错误:驱动程序无法通过使用安全套接字层(SSL)加密建立到SQL Server的安全连接

Spring JDBC + Postgres SQL + Java 8-从/到LocalDate的转换

SQL Server与Spring的连接

jdbc错误,无法连接到sql

JDBC 无法建立到 SQL Server 的 SSL 连接 (Domino Java Agent FP 9)

服务器名称中的java sql server jdbc连接字符串逗号

无法使用JDBC连接到SQL Server

无法与 SQL Server 建立多个 JDBC 连接

Java JDBC MySQL连接错误:ClassNotFoundException

使用Java JDBC连接到MS SQL数据库

R通过JDBC到SQL Server连接-驱动程序版本错误

Java连接到SQL Server并出现jtds错误

已解决与 SQL Server 的连接:java.sql.SQLException:找不到适合 jdbc:sqlserver 的驱动程序

Java SQL JDBC 错误 - 带有 Soap 消息

Java JDBC连接状态

JDBC ResultSet与SQL Server

SQL Server JDBC异常

嵌套异常是java.sql.SQLException:无法为连接URL'null'创建类''的JDBC驱动程序-Spring MVC JNDI问题

Spring无法获取JDBC连接

Oracle jdbc连接需要很长时间,然后出现“ java.sql.SQLRecoverableException:IO错误:管道断开”

连接错误SQL Server