Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

jGuru: Help: Determining Available Scalar Functions

 


[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.



    Task 1

    in doConnect(), after connecting and obtaining a Statement, add code to get DatabaseMetaData into dbmd.

          dbmd = con.getMetaData();
    

    Task 2

    In doInvokeFn(), inside a try block, add code to execute a query that returns a scalar value from the function name contained in sTemp2. Use the following query to serve as a vehicle for the scalar function:

    SELECT <scalar function expression>
    FROM JJJJData
    WHERE entry = 10

    Get the value returned in sTemp3, then close the ResultSet rs.

          rs = stmt.executeQuery( "SELECT " + 
               "{ fn " + sTemp2 + "} " + 
               "FROM JJJJData " + 
               "WHERE entry = 10" );
    
          if( rs.next() )
          {
            sTemp3 = rs.getObject( 1 ).toString();
          }
          rs.close();
    

    Task 3

    In LoadFunctions(), given the following code set,

          if( jrbNumeric.isSelected() )
          {
    
          }
          else
          if( jrbString.isSelected() )
          {
    
          }
          else
          if( jrbTD.isSelected() )
          {
    
          }
          else
          if( jrbSystem.isSelected() )
          {
    
          }
    

    retrieve the appropriate group of scalar function names into sFunctions. For jrbNumeric get the Numeric Functions, for jrbString get the String Functions, for jrbTD get the Time and Date Functions, and for jrbSystem get the System Functions.

          if( jrbNumeric.isSelected() )
          {
            sFunctions = dbmd.getNumericFunctions();
          }
          else
          if( jrbString.isSelected() )
          {
            sFunctions = dbmd.getStringFunctions();
          }
          else
          if( jrbTD.isSelected() )
          {
            sFunctions = dbmd.getTimeDateFunctions();
          }
          else
          if( jrbSystem.isSelected() )
          {
            sFunctions = dbmd.getSystemFunctions();
          }
    

    Task 4

    In LoadFunctions(), add code to get each function name from the sFunctions with a StringTokenizer st, then load the names into the data model dcbm using dcbm.addElement(). For portability, put the Strings to upper case.

            st = new StringTokenizer( sFunctions, "," );
            while( st.hasMoreTokens() )
            {
              dcbm.addElement( 
                 st.nextToken().toUpperCase() );
            }
    

Copyright 1996-2000 jGuru.com. All Rights Reserved.