无法与postgresql数据库建立连接

时间:2014-06-18 20:26:07

标签: spring hibernate postgresql

我正在使用spring 4.0.5hibernate 4.3.5开发一个Web应用程序。

当我运行xhtml页面时,我收到此错误:

java.sql.SQLException: No suitable driver

java.sql.SQLException: Connections could not be acquired from the underlying database!

我该如何解决这些问题?

这是spring的应用程序上下文文件:

<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="user" value="postgres" />
        <property name="driverClass" value="org.postgresql.Driver"/>
        <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/test" />
        <property name="password" value="toor"/>

    </bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="com.model" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key= "hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.c3p0.acquire_increment">1</prop>
            <prop key="hibernate.c3p0.minPoolSize">10</prop>
            <prop key="hibernate.c3p0.maxPoolSize">200</prop>
            <prop key="hibernate.c3p0.timeout">9999999</prop>
            <prop key="hibernate.c3p0.max_statement">0</prop> 
        </props>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

<context:annotation-config />
<context:component-scan base-package="com"/>

</beans>

对于postgresql驱动程序我正在使用postgresql-9.3-1101.jdbc4.jar

1 个答案:

答案 0 :(得分:0)

如果应用程序是J2EE应用程序,请确保postgresql-9.3-1101.jdbc4.jarWEB-INF/lib目录中,如果这是独立应用程序,请确保在类路径中。