无法将应用程序连接到数据库

发布于 2024-10-30 00:50:07 字数 3432 浏览 3 评论 0原文

我在使用 Eclipse 数据源资源管理器将 Web 应用程序连接到数据库时遇到问题。

这就是我所做的:

在此处输入图像描述

也许我确实配置了错误的驱动程序。这就是我从 eclipse Helios 配置驱动程序定义的方式。窗口 -> 首选项 -> 数据管理 -> 连接性 -> 驱动程序定义:

1

enter此处图像描述

2

此处输入图像描述

3

< img src="https://i.sstatic.net/kAuvi.png" alt="在此处输入图像描述">

4

在此处输入图像描述

我能够启动应用程序服务器,甚至通过浏览器访问应用程序。但我无法与数据库交互。 Web 应用程序的配置文件如下所示:

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="jdbc/GroupBuySystem">
<class>entities.Administ</class>
<class>entities.Buyer</class>
<class>entities.Comment</class>
<class>entities.Log</class>
<class>entities.Offer</class>
<class>entities.Seller</class>
</persistence-unit>
    </persistence>

sun-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0  Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool-name="Derby_groupbuydb_userPool"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="Derby_groupbuydb_userPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
    <property name="PortNumber" value="1527"/>
    <property name="DatabaseName" value="groupbuydb"/>
    <property name="User" value="user"/>
    <property name="Password" value="pwd"/>
    <property name="URL" value="jdbc:derby://localhost:1527/groupbuydb;create=true"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
</resources>

另外我想提一下,我使用此命令从控制台启动数据库:

C:\glassfishv3\bin>asadmin 启动数据库

在此处输入图像描述

我做错了什么?为什么我无法连接到数据库?

I have a problem connecting my Web app to the database using Eclipses datasource explorer.

This is what I did:

enter image description here

Maybe i did configure wrong the driver. This is how i configurated the driver definition from eclipse Helios. Window->Preferences->DataManagement->Conectivity->Driver Definitions:

1

enter image description here

2

enter image description here

3

enter image description here

4

enter image description here

I am able to start the application server and even access the application throgh the browser. But i cannot interact with the db. This is how the config files of the webapp look like:

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="jdbc/GroupBuySystem">
<class>entities.Administ</class>
<class>entities.Buyer</class>
<class>entities.Comment</class>
<class>entities.Log</class>
<class>entities.Offer</class>
<class>entities.Seller</class>
</persistence-unit>
    </persistence>

sun-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0  Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool-name="Derby_groupbuydb_userPool"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="Derby_groupbuydb_userPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
    <property name="PortNumber" value="1527"/>
    <property name="DatabaseName" value="groupbuydb"/>
    <property name="User" value="user"/>
    <property name="Password" value="pwd"/>
    <property name="URL" value="jdbc:derby://localhost:1527/groupbuydb;create=true"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
</resources>

Also i want to mention that i start the database from the console with this command:

C:\glassfishv3\bin>asadmin start-database

enter image description here

What am I doing wrong? Why can't I connect to the DB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2024-11-06 00:50:07

您的 jar 文件错误。对于您的驱动程序,请使用 derbyclient.jar 而不是 derby.jar

derby.jar 用于嵌入式模式下的 derby。 derbyclient.jar 用于网络/服务器模式,这就是您在连接字符串中定义的内容:

<property name="URL" value="jdbc:derby://localhost:1527/groupbuydb;create=true"/>

You have the wrong jar file. Use derbyclient.jar and not derby.jar for your driver.

derby.jar is for derby in embedded mode. derbyclient.jar is for network/server mode and that's what you have defined in your connection string:

<property name="URL" value="jdbc:derby://localhost:1527/groupbuydb;create=true"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文