2011-04-01 4 views
7

Tôi gặp sự cố khi kết nối ứng dụng web của mình với cơ sở dữ liệu bằng trình khám phá nguồn dữ liệu Eclipses.Không thể kết nối ứng dụng với cơ sở dữ liệu

Đây là những gì tôi đã làm:

enter image description here

Có lẽ tôi đã cấu hình sai người lái xe. Đây là cách tôi cấu hình định nghĩa trình điều khiển từ nhật thực Helios. Window-> Preferences-> DataManagement-> Conectivity-> Định nghĩa Driver:

enter image description here

enter image description here

enter image description here

enter image description here

tôi có thể bắt đầu các máy chủ ứng dụng và thậm chí truy cập ứng dụng throgh trình duyệt. Nhưng tôi không thể tương tác với db. Đây là cách các tập tin cấu hình của ứng dụng web như sau:

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> 

nắng 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> 

Ngoài ra tôi muốn đề cập đến mà tôi bắt đầu cơ sở dữ liệu từ bảng điều khiển với lệnh này:

C: \ glassfishv3 \ bin> asadmin khởi động cơ sở dữ liệu

enter image description here

Tôi đang làm gì sai? Tại sao tôi không thể kết nối với DB?

+0

+1 cho những hình ảnh – Ophidian

+1

Tnx :) tôi hy vọng tôi tìm ra cách để sửa lỗi này tôi đang mắc kẹt với nó và tôi không thể tiếp tục lập trình của mình. Bất kỳ ý tưởng ai đó? – sfrj

+0

Bạn có thể kết nối với máy chủ từ ứng dụng khác không?Ví dụ từ 'ij', hoặc công cụ Console từ [cơ sở dữ liệu H2] (http://h2database.com)? –

Trả lời

6

Bạn có tệp jar sai. Sử dụng derbyclient.jar và không derby.jar cho tài xế của bạn.

derby.jar là cho derby ở chế độ được nhúng. derbyclient.jar là dành cho chế độ mạng/máy chủ và đó là những gì bạn đã xác định trong chuỗi kết nối của bạn:

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