Logo of Bento frameworkspaceObject Oriented Programming


Source code example of PooledStatement


    //The SQL statement for PreparedStatement
    private String sql="INSERT INTO sometable ...";

    //Get the instance of PooledPS.
    //You need not keep the reference to it.
    //Don't worry, just a single instance can
    //be always shared within the ClassLoader.
    PooledPS pool=PooledPS.getInstance();

    PreparedStatement ps=null;
    try{
        //Get the free instance of PreparedStatement.
        //If no free instance is available in the pool,
        //wait until another instance is pushed back
        //to the pool, or create the new instance.
        ps=pool.getPS(sql);

        ps.setLong(1,id);
        ps.setString(2,amount);
        ps.executeUpdate();

        //Push it back to the pool.
        //Will be re-used.
        pool.reusePS(ps);
    }
    catch(Exception ex){
        //Push it back as the dead one.
        //Will be disposed by PooledPS,
        //i.e. the PreparedStatement and Connection
        //will be closed.
        pool.disposePS(ps);
    }


Copyright © 1997-2007 OOP-Research CorporationTM, All Rights Reserved.