⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountejb.java

📁 EJB功能实现
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   AccountEJB.java

import java.io.PrintStream;
import java.rmi.RemoteException;
import java.sql.*;
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 date;
    private String vc;
    private String check;
    private double amount;
    private EntityContext context;
    private Connection con;
    private String dbName;

    public AccountEJB()
    {
        dbName = "java:comp/env/jdbc/MyDataSource";
    }

    public String ejbFindByPrimaryKey(String s)
        throws FinderException, RemoteException
    {
        System.out.println("ejbFindByPrimaryKey()");
        boolean flag = false;
        try
        {
            flag = selectByPrimaryKey(s);
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
        if(flag)
            return s;
        else
            throw new ObjectNotFoundException("Row for id " + s + " not found");
    }

    public void setEntityContext(EntityContext entitycontext)
    {
        System.out.println("setEntityContext()");
        context = entitycontext;
        try
        {
            makeConnection();
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
    }

    public void unsetEntityContext()
    {
        System.out.println("unsetEntityContext()");
    }

    public void ejbActivate()
    {
        id = (String)context.getPrimaryKey();
        System.out.println("ejbActivate()");
    }

    public void ejbPassivate()
    {
        id = null;
        System.out.println("ejbPassivate()");
    }

    public void ejbLoad()
    {
        System.out.println("ejbLoad()");
        try
        {
            loadRow();
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
    }

    public void ejbStore()
    {
        System.out.println("ejbStore()");
        try
        {
            storeRow();
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
    }

    public String ejbCreate(String s, String s1, String s2, String s3, double d)
        throws RemoteException, CreateException
    {
        System.out.println("ejbCreate()");
        try
        {
            insertRow(s, s1, s2, s3, d);
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
        id = s;
        date = s1;
        vc = s2;
        check = s3;
        amount = d;
        return s;
    }

    public void ejbPostCreate(String s, String s1, String s2, String s3, double d)
    {
        System.out.println("ejbPostCreate()");
    }

    public void ejbRemove()
    {
        System.out.println("ejbRemove()");
        try
        {
            deleteRow(id);
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
    }

    public String getDate()
    {
        return date;
    }

    public String getVc()
    {
        return vc;
    }

    public String getCheck()
    {
        return check;
    }

    public double getAmount()
    {
        return amount;
    }

    private void makeConnection()
        throws NamingException, SQLException
    {
        InitialContext initialcontext = new InitialContext();
        DataSource datasource = (DataSource)initialcontext.lookup(dbName);
        con = datasource.getConnection();
    }

    private void deleteRow(String s)
        throws SQLException
    {
        String s1 = "delete from Account_Holder_Transaction where cAccount_Id=?";
        PreparedStatement preparedstatement = con.prepareStatement(s1);
        preparedstatement.setString(1, s);
        preparedstatement.executeUpdate();
        preparedstatement.close();
    }

    private void loadRow()
        throws SQLException
    {
        String s = "select dDate_of_transaction,vcParticulars,cCheck_no,mAmount from Account_Holder_Transaction where cAccount_Id=?";
        PreparedStatement preparedstatement = con.prepareStatement(s);
        preparedstatement.setString(1, id);
        ResultSet resultset = preparedstatement.executeQuery();
        if(resultset.next())
        {
            date = resultset.getString(1);
            vc = resultset.getString(2);
            check = resultset.getString(3);
            amount = resultset.getDouble(4);
            preparedstatement.close();
        } else
        {
            preparedstatement.close();
            throw new NoSuchEntityException("Row for id " + id + " not found in database");
        }
    }

    private void storeRow()
        throws SQLException
    {
        String s = "update Account_Holder_Transaction set dDate_of_Transaction=?,vcParticulars=?,cCheck_no=?,mAmount=? where cAccount_Id=?";
        PreparedStatement preparedstatement = con.prepareStatement(s);
        preparedstatement.setString(1, date);
        preparedstatement.setString(2, vc);
        preparedstatement.setString(3, check);
        preparedstatement.setDouble(4, amount);
        preparedstatement.setString(5, id);
        int i = preparedstatement.executeUpdate();
        preparedstatement.close();
        if(i == 0)
            throw new EJBException("Storing row for id" + id + " failed");
        else
            return;
    }

    private void insertRow(String s, String s1, String s2, String s3, double d)
        throws SQLException
    {
        String s4 = "insert into Account_Holder_Transaction values(?,?,?,?,?)";
        PreparedStatement preparedstatement = con.prepareStatement(s4);
        preparedstatement.setString(1, s);
        preparedstatement.setString(2, s1);
        preparedstatement.setString(3, s2);
        preparedstatement.setString(4, s3);
        preparedstatement.setDouble(5, d);
        preparedstatement.executeUpdate();
        preparedstatement.close();
    }

    private boolean selectByPrimaryKey(String s)
        throws SQLException
    {
        String s1 = "select cAccount_id from Account_Holder where cAccount_id = ?";
        PreparedStatement preparedstatement = con.prepareStatement(s1);
        preparedstatement.setString(1, s);
        ResultSet resultset = preparedstatement.executeQuery();
        boolean flag = resultset.next();
        preparedstatement.close();
        return flag;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -