我又试验了一下 通过远程接口调用create方法可以成功完成 连续调用几个都正常工作但是即使调用一个最简单的返回一个字段的方法也出现上面的错误 既在调用普通方法前地先调用ejbLoad()从数据库中同步数据 在ejbLoad中调用 PreparedStatement prepStmt = con.prepareStatement(selectStatement);就出现 No further JDBC access is allowed within this transaction.错误了救救我吧 我要疯了 试了很多办法都不行
而且这是一个商业方法调用中出现的错误
在这个方法之前create成功了 数据库中已经创建了数据
Container managed persistence
----------
用bmp自然是想自己控制事务了,否则用cmp好了
status:'Committed'
----------
连接不可用
No further JDBC access is allowed within this transaction.
好象是不允许在这个事务中再调用JDBC访问? 为啥呢?我自己控制事务也不样 大家再提点意见吧 我晕
transaction.setAutoCommit(false);
transaction.begin();
……操作数据库
……事务完成
transaction.commit();
你试试看
既在调用普通方法前地先调用ejbLoad()从数据库中同步数据 在ejbLoad中调用
PreparedStatement prepStmt = con.prepareStatement(selectStatement);就出现 No further JDBC access is allowed within this transaction.错误了救救我吧 我要疯了 试了很多办法都不行
import javax.ejb.EJBObject;public interface Account
extends EJBObject
{ public abstract void debit(double d)
throws InsufficientBalanceException, RemoteException; public abstract void credit(double d)
throws RemoteException; public abstract String getFirstName()
throws RemoteException; public abstract String getLastName()
throws RemoteException; public abstract double getBalance()
throws RemoteException;
}
// Source File Name: AccountHome.javaimport java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.*;public interface AccountHome
extends EJBHome
{ public abstract Account create(String s, String s1, String s2, double d)
throws RemoteException, CreateException; public abstract Account findByPrimaryKey(String s)
throws FinderException, RemoteException; public abstract Collection findByLastName(String s)
throws FinderException, RemoteException; public abstract Collection findInRange(double d, double d1)
throws FinderException, RemoteException;
}
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;public class AccountEJB
implements EntityBean
{ private String id;
private String firstName;
private String lastName;
private double balance;
private EntityContext context;
private Connection con;
private String dbName; public AccountEJB()
{
dbName = "jdbc/AccountDB";
} public void debit(double d)
throws InsufficientBalanceException
{
System.out.println("debit");
if(balance - d < 0.0D)
{
throw new InsufficientBalanceException();
} else
{
balance -= d;
return;
}
} public void credit(double d)
{
System.out.println("credit");
balance += d;
} public String getFirstName()
{
System.out.println("getFirstName");
return firstName;
} public String getLastName()
{
System.out.println("getLastName");
return lastName;
} public double getBalance()
{
System.out.println("getBalance");
return balance;
} public String ejbCreate(String s, String s1, String s2, double d)
throws CreateException
{
System.out.println("ejbCreate");
if(d < 0.0D)
throw new CreateException("A negative initial balance is not allowed.");
try
{
insertRow(s, s1, s2, d);
}
catch(Exception exception)
{
throw new EJBException("ejbCreate: " + exception.getMessage());
}
id = s;
firstName = s1;
lastName = s2;
balance = d;
return s;
} public String ejbFindByPrimaryKey(String s)
throws FinderException
{
System.out.println("ejbFindByPrimaryKey");
boolean flag;
try
{
flag = selectByPrimaryKey(s);
}
catch(Exception exception)
{
throw new EJBException("ejbFindByPrimaryKey: " + exception.getMessage());
}
if(flag)
return s;
else
throw new ObjectNotFoundException("Row for id " + s + " not found.");
} public Collection ejbFindByLastName(String s)
throws FinderException
{
System.out.println("ejbFindByLastName");
Collection collection;
try
{
collection = selectByLastName(s);
}
catch(Exception exception)
{
throw new EJBException("ejbFindByLastName " + exception.getMessage());
}
if(collection.isEmpty())
throw new ObjectNotFoundException("No rows found.");
else
return collection;
} public Collection ejbFindInRange(double d, double d1)
throws FinderException
{
System.out.println("ejbFindInRagnge");
Collection collection;
try
{
collection = selectInRange(d, d1);
}
catch(Exception exception)
{
throw new EJBException("ejbFindInRange: " + exception.getMessage());
}
if(collection.isEmpty())
throw new ObjectNotFoundException("No rows found.");
else
return collection;
} public void ejbRemove()
{
System.out.println("ejbRemove");
try
{
deleteRow(id);
}
catch(Exception exception)
{
throw new EJBException("ejbRemove: " + exception.getMessage());
}
} public void setEntityContext(EntityContext entitycontext)
{
System.out.println("setEntityContext");
context = entitycontext;
try
{
makeConnection();
}
catch(Exception exception)
{
throw new EJBException("Unable to connect to database. " + exception.getMessage());
}
} public void unsetEntityContext()
{
System.out.println("unsetEntityContext");
try
{
con.close();
}
catch(SQLException sqlexception)
{
throw new EJBException("unsetEntityContext: " + sqlexception.getMessage());
}
} public void ejbActivate()
{
System.out.println("ejbActivate");
id = (String)context.getPrimaryKey();
} public void ejbPassivate()
{
System.out.println("ejbPAssivate");
id = null;
} public void ejbLoad()
{
System.out.println("ejbLoad");
try
{
loadRow();
}
catch(Exception exception)
{
throw new EJBException("ejbLoad: " + exception.getMessage());
}
} public void ejbStore()
{
System.out.println("ejbStore");
try
{
storeRow();
}
catch(Exception exception)
{
throw new EJBException("ejbLoad: " + exception.getMessage());
}
} public void ejbPostCreate(String s, String s1, String s2, double d)
{
System.out.println("ejbPostCreate");
}