簡體   English   中英

使用Spring和Hibernate - 未知數據庫

[英]Using Spring and Hibernate — Unknown database

我有一個應用程序,我正在使用Spring和Hibernate。 我收到以下錯誤消息,即使有問題的數據庫存在。

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown database 'cpc"'

這是jcbulboard-servlet.xml的相關部分

<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:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties"></bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
        p:username="${jdbc.username}" p:password="${jdbc.password}">
    </bean>
</beans>

這是jdbc.properties,它位於正確的位置。

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://localhost/cpc"
jdbc.username=root
jdbc.password=password

這是hibernate.cfg.xml的相關部分。

    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/cpc</property>
<!-- There's more in this file, but this is all that's relevant -->
        </session-factory>
    </hibernate-configuration>

這不是Spring或Hibernate問題,而是驅動程序問題。 您的配置是正確的,但請確保您的連接網址是正確的。 我突然發現兩件事:

  1. 確保端口正確(您沒有指定端口)
  2. 確保你實際創建了數據庫cpc(CREATE DATABASE cpc)'
  3. 確保你有權實際看到數據庫(cpc。*到<user>上的各種GRANT <blah>)

jdbc.databaseurl中的尾隨雙引號可能是您的問題的原因。 嘗試刪除它。

jdbc.databaseurl=jdbc:mysql://localhost/cpc

代替

jdbc.databaseurl=jdbc:mysql://localhost/cpc"

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM