0

Trying to connect my Java Spring app on Tomcat to my sqlserver database with jdbc. Getting error:

"Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The connection to the host BEN-790, named instance sqlexpress failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.)"

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>

my 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>
2
  • You don't seem to have connection to the DB server from your machine. Are you able to connect a client tool to it ? Commented Sep 23, 2015 at 20:50
  • Yes, I can use MS SQL Server to SELECT data from the tables of the database. So I have my connection and Browser Service is running. Commented Sep 23, 2015 at 21:48

2 Answers 2

0

How about change the connection bean for this?

<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>
Sign up to request clarification or add additional context in comments.

Comments

0

+1 jpganz 18, that fixed it. I changed the class to "org.springframework.jdbc.datasource.DriverManagerDataSource" and the url to localhost:1433 and then it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.