to hesi726(hesi) 错误如下:javax.naming.NameNotFoundException: oracleDS not bound
看错误是说没找到jndi有没把oracledb-ds.xml文件放在 server\default\deploy下? 使用时要 InitialContext ict=new InitialContext(); DataSource ds=(DataSource) ict.lookup("java:/ORACLEDS"); Connection con=ds.getConnection(); 附上我用的oracledb-ds.xml文件<?xml version="1.0" encoding="UTF-8"?><!-- ===================================================================== --> <!-- --> <!-- JBoss Server Configuration --> <!-- --> <!-- ===================================================================== --><!-- $Id: hsqldb-ds.xml,v 1.1.2.4 2003/04/22 20:34:33 d_jencks Exp $ --> <datasources> <local-tx-datasource> <!-- remove this depends tag if you are not using the tcp connection url --> <!-- <depends>jboss:service=ORACLEDB</depends> --> <jndi-name>ORACLEDS</jndi-name> <!-- for tcp connection, allowing other processes to use the hsqldb database --> <connection-url>jdbc:oracle:thin:@192.168.0.107:1521:test</connection-url> <!-- for totally in-memory db, not saved when jboss stops. hsql mbean is unnecessary--> <!--connection-url>jdbc:hsqldb:.</connection-url--> <!-- for in-process db, saved when jboss stops. hsql mbean is unnecessary--> <!--connection-url>jdbc:hsqldb:default-db-name</connection-url--> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>ram</user-name> <password>ram1</password> <!--example of how to specify class that determines if exception means connection should be destroyed--> <!--exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DummyExceptionSorter</exception-sorter-class-name--> <min-pool-size>50</min-pool-size> <!-- <security-domain>ORACLEDbRealm</security-domain> --> </local-tx-datasource> <!-- this mbean should be used only when using tcp connections --> <!-- <mbean code="org.jboss.jdbc.HypersonicDatabase" name="jboss:service=ORACLEDB"> <attribute name="Port">1701</attribute> <attribute name="Silent">true</attribute> <attribute name="Database">default</attribute> <attribute name="Trace">false</attribute> <attribute name="No_system_exit">true</attribute> </mbean> --> </datasources>
把JBOSS\docs\examples\jca\oracle-ds.xml拷贝到deploy\下,编辑
----------------------------------------------------------------
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:data</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>username</user-name>
<password>pass</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
-----------------------------------------
程序里面
//数据库连接
Connection con = null; //创建JNDI上下文
Context ctx = new InitialContext(); //获得数据源
DataSource ds = (DataSource)ctx.lookup("java:/OracleDS"); //获得数据库连接
con = ds.getConnection();--------------------------
oracle驱动放到lib目录下就行了
我用jboss-3.2.1_tomcat-4.1.24的时候执行run的时候有错误
打开网页http://120.0.0.1:8080/的时候报错
deploy ,lib 目录均都时相对于 你的 server而言!
例如,default,all等!
错误如下:javax.naming.NameNotFoundException: oracleDS not bound
看错误是说没找到jndi有没把oracledb-ds.xml文件放在 server\default\deploy下?
使用时要
InitialContext ict=new InitialContext();
DataSource ds=(DataSource) ict.lookup("java:/ORACLEDS");
Connection con=ds.getConnection();
附上我用的oracledb-ds.xml文件<?xml version="1.0" encoding="UTF-8"?><!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== --><!-- $Id: hsqldb-ds.xml,v 1.1.2.4 2003/04/22 20:34:33 d_jencks Exp $ -->
<datasources>
<local-tx-datasource>
<!-- remove this depends tag if you are not using the tcp connection url -->
<!-- <depends>jboss:service=ORACLEDB</depends> -->
<jndi-name>ORACLEDS</jndi-name>
<!-- for tcp connection, allowing other processes to use the hsqldb database -->
<connection-url>jdbc:oracle:thin:@192.168.0.107:1521:test</connection-url>
<!-- for totally in-memory db, not saved when jboss stops. hsql mbean is unnecessary-->
<!--connection-url>jdbc:hsqldb:.</connection-url-->
<!-- for in-process db, saved when jboss stops. hsql mbean is unnecessary-->
<!--connection-url>jdbc:hsqldb:default-db-name</connection-url-->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>ram</user-name>
<password>ram1</password>
<!--example of how to specify class that determines if exception means connection should be destroyed-->
<!--exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DummyExceptionSorter</exception-sorter-class-name-->
<min-pool-size>50</min-pool-size>
<!-- <security-domain>ORACLEDbRealm</security-domain> -->
</local-tx-datasource> <!-- this mbean should be used only when using tcp connections -->
<!-- <mbean code="org.jboss.jdbc.HypersonicDatabase"
name="jboss:service=ORACLEDB">
<attribute name="Port">1701</attribute>
<attribute name="Silent">true</attribute>
<attribute name="Database">default</attribute>
<attribute name="Trace">false</attribute>
<attribute name="No_system_exit">true</attribute>
</mbean> -->
</datasources>
我用jsp访问session bean怎么办?!
Object obj = ctx.lookup(JNDIName);
home = (EJBHome)PortableRemoteObject.narrow(obj, EJBHomeClass);
ejb = ejbHome.create();
可是不知道怎么用