【发布时间】:2012-03-12 12:23:39
【问题描述】:
我在 windows xp 上安装了 eclipse,一切正常。我的项目是GWT with gilead hibernate,数据库是oracle。
当我决定在家工作时,我只是将整个 Eclipse 复制到我的闪存中,并将我的工作区复制到我的 Windows 7。
之后我决定从 oracle Db 转移到 mysql Db,所以我更改了整个 hibernate.cfg.xml 文件为 mysql 做好准备,我删除了 ojdbc 库并添加了 mysql 连接器。
毕竟,当我尝试运行项目时,会显示以下错误:
无法连接到数据库
就像 eclipse 正在从旧的 hibernate.cfg.xml 文件中读取一样。
那么有人知道发生了什么吗???
这是我用于 oracle 连接的 hibernate.cfg.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@IP:1521:DEVDB10GR2</property>
<property name="hibernate.connection.username">something</property>
<property name="hibernate.connection.password">something</property>
<property name="hibernate.show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="net.school.shared.hibernate.GsWorkingshift"/>
</session-factory>
</hibernate-configuration>
这是我用于 mySql 连接的 hibernate.cfg.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost /hibernatetutorial</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="net.school.shared.hibernate.GsWorkingshift"/>
</session-factory>
</hibernate-configuration>
在我这样做之后,这个错误一直在播种:
无法连接到 oracle
但是当我在我的工作电脑上尝试它时,它工作正常。
【问题讨论】:
-
你能粘贴更多的堆栈跟踪吗?
-
@imrantariq 当我从家用 PC 运行项目时,似乎 Eclipse 正在从其他地方读取 hibernate.cfg.xml。因为我什至试图更改我的 oracle 连接的用户名和密码,但什么也没发生。
-
你的班级是否正在加载 hibernate.cfg.xml?或者请确保在类路径中设置了 hibernate.cfg.xml。也许你设置了绝对路径?
-
我建议创建一个单独的 java 类来测试 jdbc 连接,方法是提供您在 hibernate.cfg.xml 文件中为 mySql 提供的这些凭据
-
@imrantariq 我将 hibernate.cfg.xml 更改为 mysql-hibernate.cfg.xml 并从中加载它,但也没有任何反应。但我忘了提到我正在使用可视源代码安全代码 vss。
标签: eclipse windows-7 windows-xp gilead hibernate.cfg.xml