Topic: 幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException)

  Print this page

1.幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) Copy to clipboard
Posted by: hzb
Posted on: 2003-06-21 11:23

各位有心人﹐我BEAN中的getConnection()方法老是報"UNABLE to get a connection from demoPool!"的錯﹐我拿它沒折了﹗幫幫忙吧﹗
  private Connection getConnection()
throws SQLException
{
//聲明初始化上下文  
InitialContext initCtx = null;
try {
initCtx = new InitialContext();
//查找數據源
DataSource ds = (javax.sql.DataSource)
initCtx.lookup("java:comp/env/jdbc/demoPool");
//返回數據源連接
return ds.getConnection();
} catch(NamingException ne) {
//有異常  
System.out.println("UNABLE to get a connection from demoPool!");
System.out.println("Please make sure that you have setup the connection pool properly");
throw new EJBException(ne);
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
System.out.println("Error closing context: " + ne);
throw new EJBException(ne);
}
}
}

==============================================
weblogic-ejb-jar.xml 如下﹕
<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN'
'http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd'>

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>beanManaged</ejb-name>
<caching-descriptor>
  <max-beans-in-cache>100</max-beans-in-cache>
</caching-descriptor>
<reference-descriptor>

<resource-description>
<res-ref-name>
jdbc/demoPool
</res-ref-name>
<jndi-name>
jdbc/examples-dataSource-demoPool
</jndi-name>
</resource-description>

</reference-descriptor>

<jndi-name>beanManaged.AccountHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

==============================================
ejb-jar.xml如下﹕
<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

<ejb-jar>
<enterprise-beans>
<entity>
  <ejb-name>beanManaged</ejb-name>
  <home>AccountHome</home>
  <remote>Account</remote>
  <ejb-class>AccountBean</ejb-class>
  <persistence-type>Bean</persistence-type>
  <prim-key-class>java.lang.String</prim-key-class>
  <reentrant>False</reentrant>

<resource-ref>
<res-ref-name>jdbc/demoPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
  <method>
   <ejb-name>beanManaged</ejb-name>
   <method-intf>Remote</method-intf>
   <method-name>*</method-name>
  </method>
  <trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

==============================================
connection pool 如下﹕
name:demoPool
url:jdbc:oracle:thin:@172.17.34.89:1521:orc1
driver classname:oracle.jdbc.driver.OracleDriver
properties:user=scott
password=tiger
dll=ocijdbc8
protocol=thin
==============================================
datasource 如下﹕
name:examples-dataSource-demoPool
jndi name:jdbc/examples-dataSource-demoPool(用examples-dataSource-demoPool試過也不行)
pool name:demoPool

2.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: yuan
Posted on: 2003-06-21 19:31

你的DataSource得到了没有?

3.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: FinalFantasy
Posted on: 2003-06-22 00:11

试试 java:comp/env/jdbc/exmples-dataSource-demoPool

4.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: hzb
Posted on: 2003-06-23 08:33

"UNABLE to get a connection from demoPool!"是自定義異常哦﹗
用"java:comp/env/jdbc/exmples-dataSource-demoPool "試了還是不行﹐
嗚,嗚,嗚,嗚,嗚,嗚....
我干脆把原程式附上﹐請幫我再看一下﹐俺感激不盡﹗

beanManaged.rar (10.72k)

5.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: why
Posted on: 2003-06-23 10:23

hzb wrote:
用"java:comp/env/jdbc/exmples-dataSource-demoPool "試了還是不行﹐

大俠的意思是"java:comp/env/jdbc/examples-dataSource-demoPool "吧?Smile

6.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: hzb
Posted on: 2003-06-23 14:32

這一句是拷貝FinalFantasy的﹐他寫錯了﹐我程式里沒錯﹐沒少"a"﹐你可以看我附件里的AccountBean.java

7.Re:幫忙的幫忙﹐想辦法的想辦法﹗﹗(weblogic NamingException) [Re: hzb] Copy to clipboard
Posted by: k_k_grass
Posted on: 2003-06-27 20:31

如果在中getConnection()加上user,pass呢?

必要时,去掉 examples-dataSource-demoPool中的‘-’线
首先你的确保datasource 没问题呵


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923