问题好像是出在 ejbStore()
因为得不到order_id的值,所以就为空,没有办法commit
请高手替我解答一下
因为得不到order_id的值,所以就为空,没有办法commit
请高手替我解答一下
解决方案 »
- 过滤器报异常,一直去除不掉,求助
- tomact启动不了?
- 图片的路径问题。。
- Axis传递附件
- Error creating bean with name 'sqlMapClient' defined in class path resource [con
- 计论Java的回调机制?
- struts+spring以及struts+ejb的问题
- 我是一位初哥,请教大家一个很简单的问题,就是怎么搭建一个xml和soap和jdom的环境?急!!!!!!!
- 如何在bmp管理的ejb中查找数据库?
- 求助,在测试环境调用webservice报错,本地却没错
- struts问题
- xml同数据库到底如何结合在一起?
OrdersPK class extends java.io.*;序列化
public OrdersPK ejbCreate(java.lang.Integer order_id,java.lang.Integer product_no,java.lang.Integer quantity) throws CreateException{PreparedStatement pstmt=null;
Connection conn=null;
try{
conn=getConnection();
pstmt=conn.prepareStatement("insert into orders (order_id,product_no,quantity) values(?,?,?)");this.order_id=order_id;this.product_no=product_no;this.quantity=quantity;pstmt.setInt(1,order_id.intValue());pstmt.setInt(2,product_no.intValue());pstmt.setInt(3,quantity.intValue());pstmt.executeUpdate();return new OrdersPK(order_id);}catch (SQLException sqle){
throw new EJBException(sqle);
}finally{
try{
if (pstmt!=null)
{
pstmt.close();
}
if (conn!=null)
{
conn.close();
}
}catch(SQLException sqle){}
}
}public OrdersPK ejbFindByPrimaryKey(OrdersPK key) throws FinderException{
System.out.println("ejbFindByPrimaryKey() called");
PreparedStatement pstmt=null;
Connection conn=null;
try{
conn=getConnection();pstmt=conn.prepareStatement("select order_id from orders where order_id=?");
pstmt.setInt(1,key.order_id.intValue());ResultSet rs=pstmt.executeQuery();
if (rs.next())
return key;
}catch(Exception e){
throw new FinderException(e.toString());
}
finally{
try{
if (pstmt!=null) pstmt.close();
}catch (Exception e){}
try {
if (conn!=null) conn.close();
}catch (Exception e){}
}
}
}public void ejbLoad(){
System.out.println("ejbLoad() called");
OrdersPK key=(OrdersPK)ctx.getPrimaryKey();
System.out.println("key is"+key.toString());
java.lang.Integer order_id=key.order_id;
PreparedStatement pstmt=null;
Connection conn=null;
try{
conn=getConnection();pstmt=conn.prepareStatement("select order_id,product_no,quantity from orders where order_id=?");
pstmt.setInt(1,key.order_id.intValue());
ResultSet rs=pstmt.executeQuery();
rs.next();
order_id=rs.getString("order_id");
product_no=new Integer(rs.getInt("product_no"));
System.out.println("**load:product_no is"+product_no.toString());
quantity=new Integer(rs.getInt("quantity"));
}catch(Exception ex){
throw new EJBException("failed to load from the database"+ex);
}finally{System.out.println("order_id is"+order_id.toString());
try{
if (pstmt!=null) pstmt.close();
}catch (Exception e){}
try {
if (conn!=null) conn.close();
}catch (Exception e){}
}
}public void ejbStore(){
System.out.println("ejbStore() called");
PreparedStatement pstmt=null;
Connection conn=null;
try{
conn=getConnection();pstmt=conn.prepareStatement("update orders set product_no=?,quantity=? where order_id=?");
pstmt.setInt(1,product_no.intValue());
pstmt.setInt(2,quantity.intValue());
pstmt.setInt(3,order_id.intValue());
pstmt.executeUpdate();
}catch(Exception ex){
throw new EJBException("failed to save to the database",ex);
}
finally{
try{
if (pstmt!=null) pstmt.close();
}catch (Exception e){}
try {
if (conn!=null) conn.close();
}catch (Exception e){}
}
}
public void ejbRemove() throws RemoveException{
System.out.println("ejbRemove() called");PreparedStatement pstmt=null;
Connection conn=null;
try{
conn=getConnection();pstmt=conn.prepareStatement("delete from orders where order_id=?");
pstmt.setInt(1,order_id.intValue());if (pstmt.executeUpdate()==0){
throw new RemoveException("failed to operate the database");
}
}catch(Exception ex){
throw new EJBException(ex.toString());
}
finally{
try{
if (pstmt!=null) pstmt.close();
}catch (Exception e){}
try {
if (conn!=null) conn.close();
}catch (Exception e){}
}
}