Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't get DB Connection using JNDI datasource on JBoss
    text
    copied!<p>I'm studying how to build java webapps for JBossAS 5.1.0 and I'm trying to build a very basic jsp web app on JBossAS5 using a JNDI datasource for data access. </p> <p>When trying to open a connection I get this exception:</p> <pre><code>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) </code></pre> <p>The datasource is deployed ok, I can see it in the jmx-console &amp; the database files are getting created ok.</p> <p>Java code in question where the exception is thrown:</p> <pre><code>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; } </code></pre> <p>web.xml:</p> <pre><code>&lt;web-app&gt; &lt;resource-ref&gt; &lt;res-ref-name&gt;jdbc/hedgehogDB&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt; &lt;/web-app&gt; </code></pre> <p>jboss-web.xml:</p> <pre><code>&lt;jboss-web&gt; &lt;resource-ref&gt; &lt;res-ref-name&gt;jdbc/hedgehogDB&lt;/res-ref-name&gt; &lt;jndi-name&gt;java:/hedgehogDB&lt;/jndi-name&gt; &lt;/resource-ref&gt; &lt;/jboss-web&gt; </code></pre> <p>hedgehogdb-ds.xml</p> <pre><code>&lt;datasources&gt; &lt;local-tx-datasource&gt; &lt;jndi-name&gt;hedgehogDB&lt;/jndi-name&gt; &lt;connection-url&gt;jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}hedgehogDB&lt;/connection-url&gt; &lt;driver-class&gt;org.hsqldb.jdbcDriver&lt;/driver-class&gt; &lt;user-name&gt;sa&lt;/user-name&gt; &lt;password&gt;&lt;/password&gt; &lt;min-pool-size&gt;5&lt;/min-pool-size&gt; &lt;max-pool-size&gt;20&lt;/max-pool-size&gt; &lt;idle-timeout-minutes&gt;0&lt;/idle-timeout-minutes&gt; &lt;track-statements/&gt; &lt;security-domain&gt;HsqlDbRealm&lt;/security-domain&gt; &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt; &lt;metadata&gt; &lt;type-mapping&gt;Hypersonic SQL&lt;/type-mapping&gt; &lt;/metadata&gt; &lt;depends&gt;jboss:service=Hypersonic,database=hedgehogDB&lt;/depends&gt; &lt;/local-tx-datasource&gt; &lt;mbean code="org.jboss.jdbc.HypersonicDatabase" name="jboss:service=Hypersonic,database=hedgehogDB"&gt; &lt;attribute name="Database"&gt;hedgehogDB&lt;/attribute&gt; &lt;attribute name="InProcessMode"&gt;true&lt;/attribute&gt; &lt;/mbean&gt; &lt;/datasources&gt; </code></pre> <p>This is my first time in this environment and I suspect that I'm missing something really basic.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload