Tôi đang nghiên cứu cách xây dựng ứng dụng web java cho JBossAS 5.1.0 và tôi đang cố gắng xây dựng một ứng dụng web jsp rất cơ bản trên JBossAS5 bằng cách sử dụng nguồn dữ liệu JNDI để truy cập dữ liệu .không thể kết nối DB bằng cách sử dụng nguồn dữ liệu JNDI trên JBoss
Khi cố gắng để mở một kết nối tôi nhận được ngoại lệ này:
21:42:52,834 ERROR [STDERR] Cannot get connection: org.jboss.util.NestedSQLException:
Unable to get managed connection for hedgehogDB; - nested throwable:
(javax.resource.ResourceException: Unable to get managed connection for hedgehogDB)
Các nguồn dữ liệu được triển khai ok, tôi có thể nhìn thấy nó trong jmx-console & các tập tin cơ sở dữ liệu đang nhận được tạo ra ok.
mã Java trong câu hỏi mà ngoại lệ được ném:
static public Connection getHedgehogConnection()
{
Connection result = null;
try
{
String DS_Context = "java:comp/env/jdbc/hedgehogDB";
Context initialContext = new InitialContext();
if (initialContext == null)
log("JNDI problem. Cannot get InitialContext.");
DataSource datasource = (DataSource)initialContext.lookup(DS_Context);
if (datasource != null)
result = datasource.getConnection();
else
log("Failed: datasource was null");
}
catch(Exception ex)
{
log("Cannot get connection: " + ex);
}
return result;
}
web.xml:
<web-app>
<resource-ref>
<res-ref-name>jdbc/hedgehogDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
JBoss-web.xml:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/hedgehogDB</res-ref-name>
<jndi-name>java:/hedgehogDB</jndi-name>
</resource-ref>
</jboss-web>
hedgehogdb-ds.xml
<datasources>
<local-tx-datasource>
<jndi-name>hedgehogDB</jndi-name>
<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}hedgehogDB</connection-url>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<user-name>sa</user-name>
<password></password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>0</idle-timeout-minutes>
<track-statements/>
<security-domain>HsqlDbRealm</security-domain>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<metadata>
<type-mapping>Hypersonic SQL</type-mapping>
</metadata>
<depends>jboss:service=Hypersonic,database=hedgehogDB</depends>
</local-tx-datasource>
<mbean code="org.jboss.jdbc.HypersonicDatabase"
name="jboss:service=Hypersonic,database=hedgehogDB">
<attribute name="Database">hedgehogDB</attribute>
<attribute name="InProcessMode">true</attribute>
</mbean>
</datasources>
Đây là lần đầu tiên tôi ở trong môi trường này và tôi nghi ngờ rằng tôi thiếu một số thứ thực sự cơ bản.
tập tin - kỳ quặc, không ai trong số những ví dụ tôi đã nhìn thấy sử dụng rằng, nó có thể được yêu cầu cho kiểu kết nối jdbc DriverManager, thay đổi nó gây ra nhiều ngoại lệ – Dana
Cảm ơn lời nhắc Log4J, mã thử nghiệm khó chịu của tôi :-( – Dana