FileDocCategorySizeDatePackage
StoredProcUtil.javaAPI DocExample1912Tue Jul 22 16:01:54 BST 2003com.jspservletcookbook

StoredProcUtil

public class StoredProcUtil extends Object

Fields Summary
private static DataSource
pool
private static Context
env
Constructors Summary
Methods Summary
public static voidaddRaceEvent(java.lang.String name, java.lang.String location, java.lang.String date)

 
      try{
           
             env = (Context) new InitialContext().lookup("java:comp/env");
             
             pool  = (DataSource) env.lookup("jdbc/oracle-8i-athletes");
             
             if (pool == null)
                 throw new Exception("'oracle-8i-athletes' is an unknown DataSource");
             
        } catch (Exception e) { 
        
            System.out.println(e);

        }
 
 
    
        if( (! check(name)) || (! check(location)) || (! check(date)))
            throw new IllegalArgumentException("Invalid param values passed to addRaceEvent()");
            
        Connection conn = null;
        
        try{
        
        conn = pool.getConnection();
        
        if (conn == null )
           throw new SQLException("Invalid Connection in addRaceEvent method");
        
        CallableStatement cs = null;
        
        //Create an instance of the CallableStatement
        cs = conn.prepareCall( "{call addEvent (?,?,?)}" );
        
        cs.setString(1,name); 
        cs.setString(2,location); 
        cs.setString(3,date); 
        
        //Call the inherited PreparedStatement.executeUpdate() method
        cs.executeUpdate();
        
       // return the connection to the pool
       conn.close();
       
       } catch (SQLException sqle) { }
       

  
private static booleancheck(java.lang.String value)

    
        if(value == null || value.equals(""))
            return false;
            
        return true;