Announcement Announcement Module
Collapse
No announcement yet.
"Could not get JDBC Connection" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "Could not get JDBC Connection"

    I've been tryin for 2 days now to figure this out, and all for nothing...
    I have a Sql Server 2005 database which i use in my java app. I work in eclipse and i have no problem connecting to my DB using SqlExplorer plugin, queries work just fine, but when i run my app i get this :

    Code:
    Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The TCP/IP connection to the host JOANNA-PCSQLEXPRESS, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".)
    I checked and SqlServer accepts TCP/IP connections, port is 1433, i even added exceptions in my win firewall for sqlserver.

    My appContext.xml looks like this:

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

    <bean id="adminDep" class="depozit.DepozitAdministratorJDBC">
    <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${db.driver}" />
    <property name="url" value="${db.url}" />
    <property name="username" value="${db.user}" />
    <property name="password" value="${db.pw}" />
    </bean>

    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>build.properties</value>
    </list>
    </property>
    </bean>


    </beans>

    And build.properties:

    db.driver=com.microsoft.sqlserver.jdbc.SQLServerDr iver
    db.url=jdbc:sqlserver://JOANNA-PC\SQLEXPRESS;databaseName=Universitate;
    db.user=sa
    db.pw=proiect

    What's wrong?
    Last edited by ioanamincic; Mar 7th, 2010, 01:16 PM.

  • #2
    There is clearly a problem with the URL that you are using because it thinks that the host name is: "JOANNA-PCSQLEXPRESS".

    Try adding a second backslash in the url since it is being read from a properties file and it is probably trying to escape the 'S' in SQLEXPRESS when the properties are loaded:

    Code:
    db.url=jdbc:sqlserver://JOANNA-PC\\SQLEXPRESS;databaseName=Universitate;

    Comment


    • #3
      Thanks very much problem solved

      Comment

      Working...
      X