【发布时间】:2011-01-12 19:07:30
【问题描述】:
在 J2EE 应用程序中设置 JDBC 连接时,除了数据库名称之外,还需要指定模式名称吗?
我已经关注了这个tutorial 并设置了一个数据库和用户名/密码,但是当我启动我的应用程序时我遇到了这个错误。 DBUnit 是否有可能在 hibernate 启动和创建模式之前尝试插入数据?
Caused by: org.dbunit.dataset.NoSuchTableException: Did not find table 'CLIENT' in schema 'null'
我的连接详情如下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/salestracker"/>
<property name="username" value="salestracker"/>
<property name="password" value="salestracker"/>
</bean>
我已经创建了数据库:
[james@nevada sales-tracker]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.42 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| salestracker |
| test |
+--------------------+
4 rows in set (0.00 sec)
我是否需要在我的 hibernate persistence.xml 中指定“使用”特定数据库的内容?我假设这将隐含在 JDBC URL 中
【问题讨论】:
-
在您的
salestracker数据库中,您有一个CLIENT表吗? -
数据库是空的,我在休眠中有这个,我相信它应该为我创建数据库结构:
<!--Automatically create the SQL schema --> <property name="hibernate.hbm2ddl.auto" value="create"/> -
有时 hibernate 在生成模式时遇到问题,它会在日志中恰当地报告。检查表是否存在,然后检查日志
标签: java mysql hibernate spring jdbc