具体点...
出错信息
代码...
配置信息 ------------------------------------------------------
           我们还年轻牛奶会有的奶牛也会有的 
             可天天在 csdn 混这些会有吗 ??

解决方案 »

  1.   

    出错信息就是  CONM6000W:在事务中非法使用 1PC 资源 没了,配置是设置了2个数据源,
    jndi/test1 和 jndi/test2 分别对应不同的库。
    private Connection getConnection(int Type)
    {
    try{
            Context ctx=new InitialContext();
            
            switch(Type)
            {
             case 0:
             setJndiName("jdbc/test1");
             break;
             case 1:
             setJndiName("jdbc/test2");
             break;
            }
            
                DataSource ds=(DataSource)ctx.lookup(jndiName);
                return ds.getConnection();
    }
    catch (Exception e)
    {
    return null;
    }
    }这是取得连接,返回也正常,只是在从SessionBean中出来的时候在外面的jsp中抛出异常。
      

  2.   

    ,只是在从SessionBean中出来的时候在外面的jsp中抛出异常。 ????
      

  3.   

    是的,我跟踪过,是在部署代码中抛出的异常,但是数据都已经取到了,这是ws4.06中,如果是ws5.0中,在第二次调用createstatment的时候会抛出异常。
      

  4.   

    大家务必要帮忙啊,下面是我测试用的最简代码,也是同样的问题:package atmms.sample;import java.sql.*;
    import javax.sql.*; 
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.*;
    import java.util.*;
    /**
     * Bean implementation class for Enterprise Bean: Sample
     */
    public class SampleBean implements javax.ejb.SessionBean {
    private javax.ejb.SessionContext mySessionCtx;
    /**
     * getSessionContext
     */
    public javax.ejb.SessionContext getSessionContext() {
    return mySessionCtx;
    }
    /**
     * setSessionContext
     */
    public void setSessionContext(javax.ejb.SessionContext ctx) {
    mySessionCtx = ctx;
    }
    /**
     * ejbCreate
     */
    public void ejbCreate() throws javax.ejb.CreateException {
    }
    /**
     * ejbActivate
     */
    public void ejbActivate() {
    }
    /**
     * ejbPassivate
     */
    public void ejbPassivate() {
    }
    /**
     * ejbRemove
     */
    public void ejbRemove() {
    }

    private Vector v1 = new Vector();

    private Vector v2 = new Vector();

    public boolean getList()
    {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    Connection con1 = null;
    Statement stmt1 = null;
    ResultSet rs1 = null;
     
    try
    {
    con = getConnection1();  
    String sql = "select * from USERINFO";    
    stmt = con.createStatement();
    rs = stmt.executeQuery(sql);
    rs.close();
    stmt.close();
    con.close();


    con1 = getConnection2();  
    String sql1 = "select * from ATMRCD";    
    stmt1 = con1.createStatement();
    rs1 = stmt1.executeQuery(sql1);
     
    }
    catch(Exception e)
    {
    return false;  
    }
    return true;  
    }

    /**
     * 获得数据库连接    
     */
    private Connection getConnection1() throws Exception
        {
         //String jndiName = getDBJndiName();
            try
            {
                Context ctx=new InitialContext();
                DataSource ds=(DataSource)ctx.lookup("jdbc/test1");
                return ds.getConnection();
            }
            catch(Exception e)
            {
                throw new Exception("连接数据库失败:"+e.toString());
            }
        }
        
        private Connection getConnection2() throws Exception
        {
         //String jndiName = getDBJndiName();
            try
            {
                Context ctx=new InitialContext();
                DataSource ds=(DataSource)ctx.lookup("jdbc/test2");
                return ds.getConnection();
            }
            catch(Exception e)
            {
                throw new Exception("连接数据库失败:"+e.toString());
            }
        }
    }
      

  5.   

    你在调用另一个connection的时候,把前一个connection和statement全部释放试一下
      

  6.   

    stmt = con.createStatement();
    rs = stmt.executeQuery(sql);
    rs.close();
    stmt.close();
    con.close();看这段测试程序,都已经释放了,不过还是没用。
      

  7.   

    好久没玩ejb,,,都忘了!! :(
      

  8.   

    con = getConnection1();  
    String sql = "select * from USERINFO";    
    stmt = con.createStatement();
    rs = stmt.executeQuery(sql);
    rs.close();
    stmt.close();
    con.close();
    con1 = getConnection2();  
    String sql1 = "select * from ATMRCD";    
    stmt1 = con1.createStatement();
    rs1 = stmt1.executeQuery(sql1);
    这样写也会出错吗?
    我在JBoss中配过两个连接池,不过是EJB用一个,JSP页面中有时又用了另一个,没出过错~
    你把那个方法的事务属性去掉试试~
      

  9.   

    这是没问题的,我知道,但是在一个ejb里面用2个就不行,你们可以把那段代码测试一下就知道了
      

  10.   

    只能同情你~
    一个EJB中要用两个连接:)
      

  11.   

    建两个??你是说分别实例化2个吗?我2个DataSource分别是写在2个函数里的。应该没问题吧。
      

  12.   

    /**
         * 关闭数据库
         */
        public void dbClose() {
            try {
                rs.close();
                db.close();
                Logger.info("数据库已关闭");        } catch (Exception ex) {
                Logger.error(ex.getMessage(), ex);
            } finally {
                if (rs != null)
                    try {
                        rs.close();
                    } catch (Exception ex) {
                        Logger.error(ex.getMessage(), ex);
                    }
                if (db != null) {
                    try {
                        db.close();
                    } catch (Exception ex) {
                        Logger.error(ex.getMessage(), ex);
                    }
                }
            }
        }