好象是事务出了问题,看看你的事物吧,
你没写jdbc的事务吧?
你没写jdbc的事务吧?
解决方案 »
- 谁有effective java 中文第二版的电子书吗
- weblogic console端口在哪修改(在线等.............)
- java 创建excel副本出现空指针异常!!
- 急求jsp+javamail带附件发送邮件的源码. .....高分
- HIBERNATE连接问题
- 郁闷三天的小问题
- Tomcat的配置,我下载了tomcat5.0,安装后有问题
- 现在开发JAVA程序用的最多或最好用的工具是什么啊?????????
- 菜鸟请教各位仁兄:我在sessionbean里写了一个调用entitybean(Employee)的方法,如getEmployee(),返回值为Employy实体bean对象,编译环境
- 如何在视图上建实体EJB?
- 怎样提高lucence搜索精度?
- style report能集成到JBx 和weblogic 8.1吗?支持c/s下java报表开发吗?解答都高分相送100 另开贴再送分200
而且这是一个商业方法调用中出现的错误
在这个方法之前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");
}