我在Application Server PE 8中配置了JDBC数据源,jndi名称是jdbc/WebTop,然后我在客户端远程调用EJB,并且在EJB中调用如下代码连接数据库时出错。代码如下:Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("java:comp/env/jdbc/WebTop");
Connection connection = ds.getConnection();ejb-jar.xml:<ejb-jar xmlns = "http://java.sun.com/xml/ns/j2ee" version = "2.1" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>UserEventsJar</display-name>
<enterprise-beans>
<session>
<display-name>UserEventsEjb</display-name>
<ejb-name>UserEventsEjb</ejb-name>
<home>jax.webtop.struts.ejb.EJBUserEventsHome</home>
<remote>jax.webtop.struts.ejb.EJBUserEventsObject</remote>
<ejb-class>jax.webtop.struts.ejb.EJBUserEventsBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>jdbc/WebTop</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>sun-ejb-jar.xml:<sun-ejb-jar>
<enterprise-beans>
<unique-id>1</unique-id>
<ejb>
<ejb-name>UserEventsEjb</ejb-name>
<jndi-name>UserEventsJndi</jndi-name>
<resource-ref>
<res-ref-name>jdbc/WebTop</res-ref-name>
<jndi-name>jdbc/WebTop</jndi-name>
</resource-ref>
</ejb>
</enterprise-beans>
</sun-ejb-jar>anybody any ideas ? pls help me ! thx !
DataSource ds = (DataSource)initContext.lookup("java:comp/env/jdbc/WebTop");
Connection connection = ds.getConnection();ejb-jar.xml:<ejb-jar xmlns = "http://java.sun.com/xml/ns/j2ee" version = "2.1" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>UserEventsJar</display-name>
<enterprise-beans>
<session>
<display-name>UserEventsEjb</display-name>
<ejb-name>UserEventsEjb</ejb-name>
<home>jax.webtop.struts.ejb.EJBUserEventsHome</home>
<remote>jax.webtop.struts.ejb.EJBUserEventsObject</remote>
<ejb-class>jax.webtop.struts.ejb.EJBUserEventsBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>jdbc/WebTop</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>sun-ejb-jar.xml:<sun-ejb-jar>
<enterprise-beans>
<unique-id>1</unique-id>
<ejb>
<ejb-name>UserEventsEjb</ejb-name>
<jndi-name>UserEventsJndi</jndi-name>
<resource-ref>
<res-ref-name>jdbc/WebTop</res-ref-name>
<jndi-name>jdbc/WebTop</jndi-name>
</resource-ref>
</ejb>
</enterprise-beans>
</sun-ejb-jar>anybody any ideas ? pls help me ! thx !
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货