调用如下:
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
我觉得可能是你的调用部分不太对。

解决方案 »

  1.   

    ctx.lookup("java:/Sample")中的lookup("")中的内容是你的数据源的名字
    再者InitialContext ctx=new InitialContext();不建议这样写
      

  2.   

    ctx.lookup("java:/Sample")中的lookup("")中的内容是你的数据源的名字
    再者InitialContext ctx=new InitialContext();不建议这样写
      

  3.   

    DataSource ds=(DataSource)ctx.lookup("java:/Sample"); 
    中的lookup中的数据应该是数据源的名字
    再者InitialContext ctx=new InitialContext();
    不建议这样写 
      

  4.   

    我觉得有连接就应该又关闭
    你第1次可以 应该连接是关闭的打开
    第2次 连接本来就是打开的 再打开就抛异常了个人观点 很多情况下都这样  JBOSS不熟悉
      

  5.   

    con=ds.getConnection();
    psql=con.prepareStatement( "select   customerid,name,address   from   customer   where   name   like   ? ");
    String   par=request.getParameter( "parm ");
    if(par==null)par= " ";
    else   {par=new   String(par.getBytes( "iso-8859-1 "));}
    psql.setString(1, "% "+par+ "% ");
    rs=psql.executeQuery(); con.close();试下看看
      

  6.   

    server.xml的配置贴上来啊.没有配置怎么叫别人帮你找问题??????
      

  7.   

          Context initialContext = new InitialContext();
          DataSource dataSource = (DataSource) initialContext
              .lookup("java:/Sample "));
    你的Sample后面的空格是做什么的?
      

  8.   

    这是mssql-ds.xml的配置文件:
    - <datasources>
    - <local-tx-datasource>
      <jndi-name>Sample</jndi-name> 
      <connection-url>jdbc:sqlserver://localhost:1433;DatabaseName=sample</connection-url> 
      <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class> 
      <user-name>sa</user-name> 
      <password /> 
    - <!--  sql to call when connection is created
            <new-connection-sql>some arbitrary sql</new-connection-sql>
            
      --> 
    - <!--  sql to call on an existing pooled connection when it is obtained from pool 
            <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
            
      --> 
    - <!--  corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) 
      --> 
    - <metadata>
      <type-mapping>MS SQLSERVER2000</type-mapping> 
      </metadata>
      </local-tx-datasource>
      </datasources>
    Sample没写空格啊,不是这个原因啦。第一次启动服务器是能运行出来,关了网页然后再运行就出现刚开始说得异常了。
    而且异常是出现在con=ds.getConnection(); 这句以后。请大家再帮忙看看吧。谢谢啦!
      

  9.   

    关于上面的配置文件我在说明一下:
    我用的JDBC驱动程序是Microsoft SQL Server 2005 JDBC Driver,它和sql 2000配置有点不同,配置文件应该是没问题的。
      

  10.   

    问题终于解决了:我把原来导入/WebContent/WEB-INF/lib中的sqljdbc.jar放到\jboss-4.0.4.GA\server\default\lib这个目录下以后就可以了,谢谢大家了!