Announcement Announcement Module
Collapse
No announcement yet.
Trouble connect to PstgreSQL Database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble connect to PstgreSQL Database

    Hi,

    Throwing exception when connecting to Postgresql Database, hosted on local machine. Database settings seem fine.

    JDBC Properties file (resource folder)

    jdbc.driverClassName=org.postgresql.Driver
    jdbc.url=jdbcostgresql://localhost/db
    jdbc.username=private
    jdbc.password=private


    #app-context-annotation.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:jee="http://www.springframework.org/schema/jee"
        
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/jdbc 
            http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
    
    
     <context:component-scan base-package="com.app.core.member.jdbc.annotation"/>
    <context:annotation-config/>
    <bean id="memberDao" class="com.app.core.dao.impl.JdbcMemberDao">
    	<property name="dataSource">
    	<ref local="dataSource" />
    	</property>
    </bean>
    
    
    </beans>
    #datasource-drivermanager.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName">
                <value>${jdbc.driverClassName}</value>
            </property>
            <property name="url">
                <value>${jdbc.url}</value>
            </property>
            <property name="username">
                <value>${jdbc.username}</value>
            </property>
            <property name="password">
                <value>${jdbc.password}</value>
            </property>
        </bean>
    
        <context:property-placeholder location="jdbc.properties" />
    </beans>
    INFO : org.springframework.beans.factory.xml.XmlBeanDefin itionReader - Loading XML bean definitions from URL [file:/home/foo/workspace/App/target/test-classes/app-context-annotation.xml]
    INFO : org.springframework.context.annotation.ClassPathBe anDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
    INFO : org.springframework.beans.factory.xml.XmlBeanDefin itionReader - Loading XML bean definitions from URL [file:/home/foo/workspace/App/target/classes/app-context-annotation.xml]
    INFO : org.springframework.context.annotation.ClassPathBe anDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
    INFO : org.springframework.context.support.GenericXmlAppl icationContext - Refreshing org.springframework.context.support.GenericXmlAppl icationContext@1dfa490: startup date [Tue Jun 12 20:49:04 BST 2012]; root of context hierarchy
    INFO : org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    INFO : org.springframework.beans.factory.support.DefaultL istableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1190ae9: defining beans [org.springframework.context.annotation.internalCon figurationAnnotationProcessor,org.springframework. context.annotation.internalAutowiredAnnotationProc essor,org.springframework.context.annotation.inter nalRequiredAnnotationProcessor,org.springframework .context.annotation.internalCommonAnnotationProces sor,memberDao,dataSource,org.springframework.conte xt.annotation.ConfigurationClassPostProcessor$Impo rtAwareBeanPostProcessor#0]; root of factory hierarchy
    Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not get JDBC Connection; nested exception is org.postgresql.util.PSQLException: Protocol error. Session setup failed.
    at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:573)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:637)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:662)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:702)
    at org.springframework.jdbc.object.SqlQuery.execute(S qlQuery.java:112)
    at org.springframework.jdbc.object.SqlQuery.execute(S qlQuery.java:122)
    at org.springframework.jdbc.object.SqlQuery.execute(S qlQuery.java:137)
    at com.app.core.dao.impl.JdbcMemberDao.findAll(JdbcMe mberDao.java:33)
    at com.app.core.AnnotationJdbcMembersSample.main(Anno tationJdbcMembersSample.java:19)
    Caused by: org.postgresql.util.PSQLException: Protocol error. Session setup failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAut hentication(ConnectionFactoryImpl.java:409)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openC onnectionImpl(ConnectionFactoryImpl.java:108)
    at org.postgresql.core.ConnectionFactory.openConnecti on(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init >(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init >(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3C onnection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:3 93)
    at org.postgresql.Driver.connect(Driver.java:267)
    at java.sql.DriverManager.getConnection(DriverManager .java:579)
    at java.sql.DriverManager.getConnection(DriverManager .java:190)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan agerDataSource.java:173)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriver(DriverManagerDat aSource.java:164)
    at org.springframework.jdbc.datasource.AbstractDriver BasedDataSource.getConnectionFromDriver(AbstractDr iverBasedDataSource.java:149)
    at org.springframework.jdbc.datasource.AbstractDriver BasedDataSource.getConnection(AbstractDriverBasedD ataSource.java:119)
    at org.springframework.jdbc.datasource.DataSourceUtil s.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtil s.getConnection(DataSourceUtils.java:77)
    ... 9 more
Working...
X