Private

profilehelpneded
20160709225955javadb_week5_3.zip

JavaDB Week5-3/.classpath

__MACOSX/JavaDB Week5-3/._.classpath

JavaDB Week5-3/.DS_Store

__MACOSX/JavaDB Week5-3/._.DS_Store

JavaDB Week5-3/.project

JavaDB Week5 org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature

__MACOSX/JavaDB Week5-3/._.project

JavaDB Week5-3/.settings/org.eclipse.jdt.core.prefs

eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8

__MACOSX/JavaDB Week5-3/.settings/._org.eclipse.jdt.core.prefs

__MACOSX/JavaDB Week5-3/._.settings

JavaDB Week5-3/bin/Animal.class

synchronized class Animal {
    private String name;
    private String color;
    private boolean swim;
    private boolean vertebrate;
    public void Animal(String, String, boolean, boolean);
    public String getName();
    public void setName(String);
    public String getColor();
    public void setColor(String);
    public boolean getSwim();
    public void setSwim(boolean);
    public boolean getVertebrate();
    public void setVertebrate(boolean);
    public String toString();
}

__MACOSX/JavaDB Week5-3/bin/._Animal.class

JavaDB Week5-3/bin/AnimalDataAccessor.class

public synchronized class AnimalDataAccessor {
    private String framework;
    private String driver;
    private String protocol;
    public void AnimalDataAccessor();
    public static void main(String[]);
    void go(String[]);
    private void loadDriver();
    private void reportFailure(String);
    public static void printSQLException(java.sql.SQLException);
    private void parseArguments(String[]);
}

__MACOSX/JavaDB Week5-3/bin/._AnimalDataAccessor.class

__MACOSX/JavaDB Week5-3/._bin

JavaDB Week5-3/derby.log

---------------------------------------------------------------- Sun Jul 03 12:56:03 EAT 2016: Booting Derby version The Apache Software Foundation - Apache Derby - 10.8.2.2 - (1181258): instance a816c00e-0155-b02f-adeb-000001c5df60 on database directory C:\Users\Fayee\workspace\JavaDB Week5\derbyDB with class loader sun.misc.Launcher$AppClassLoader@73d16e93 Loaded from file:/C:/Program%20Files/Java/jdk1.8.0_92/jre/lib/ext/derby.jar java.vendor=Oracle Corporation java.runtime.version=1.8.0_92-b14 user.dir=C:\Users\Fayee\workspace\JavaDB Week5 derby.system.home=null Database Class Loader started - derby.database.classpath='' ---------------------------------------------------------------- Sun Jul 03 12:56:04 EAT 2016: Shutting down Derby engine ---------------------------------------------------------------- Sun Jul 03 12:56:05 EAT 2016: Shutting down instance a816c00e-0155-b02f-adeb-000001c5df60 on database directory C:\Users\Fayee\workspace\JavaDB Week5\derbyDB with class loader sun.misc.Launcher$AppClassLoader@73d16e93 ----------------------------------------------------------------

__MACOSX/JavaDB Week5-3/._derby.log

JavaDB Week5-3/derbyDB/log/log.ctrl

__MACOSX/JavaDB Week5-3/derbyDB/log/._log.ctrl

JavaDB Week5-3/derbyDB/log/log1.dat

__MACOSX/JavaDB Week5-3/derbyDB/log/._log1.dat

JavaDB Week5-3/derbyDB/log/logmirror.ctrl

__MACOSX/JavaDB Week5-3/derbyDB/log/._logmirror.ctrl

__MACOSX/JavaDB Week5-3/derbyDB/._log

JavaDB Week5-3/derbyDB/seg0/c10.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c10.dat

JavaDB Week5-3/derbyDB/seg0/c101.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c101.dat

JavaDB Week5-3/derbyDB/seg0/c111.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c111.dat

JavaDB Week5-3/derbyDB/seg0/c121.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c121.dat

JavaDB Week5-3/derbyDB/seg0/c130.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c130.dat

JavaDB Week5-3/derbyDB/seg0/c141.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c141.dat

JavaDB Week5-3/derbyDB/seg0/c150.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c150.dat

JavaDB Week5-3/derbyDB/seg0/c161.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c161.dat

JavaDB Week5-3/derbyDB/seg0/c171.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c171.dat

JavaDB Week5-3/derbyDB/seg0/c180.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c180.dat

JavaDB Week5-3/derbyDB/seg0/c191.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c191.dat

JavaDB Week5-3/derbyDB/seg0/c1a1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1a1.dat

JavaDB Week5-3/derbyDB/seg0/c1b1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1b1.dat

JavaDB Week5-3/derbyDB/seg0/c1c0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1c0.dat

JavaDB Week5-3/derbyDB/seg0/c1d1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1d1.dat

JavaDB Week5-3/derbyDB/seg0/c1e0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1e0.dat

JavaDB Week5-3/derbyDB/seg0/c1f1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c1f1.dat

JavaDB Week5-3/derbyDB/seg0/c20.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c20.dat

JavaDB Week5-3/derbyDB/seg0/c200.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c200.dat

JavaDB Week5-3/derbyDB/seg0/c211.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c211.dat

JavaDB Week5-3/derbyDB/seg0/c221.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c221.dat

JavaDB Week5-3/derbyDB/seg0/c230.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c230.dat

JavaDB Week5-3/derbyDB/seg0/c241.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c241.dat

JavaDB Week5-3/derbyDB/seg0/c251.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c251.dat

JavaDB Week5-3/derbyDB/seg0/c260.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c260.dat

JavaDB Week5-3/derbyDB/seg0/c271.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c271.dat

JavaDB Week5-3/derbyDB/seg0/c281.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c281.dat

JavaDB Week5-3/derbyDB/seg0/c290.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c290.dat

JavaDB Week5-3/derbyDB/seg0/c2a1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2a1.dat

JavaDB Week5-3/derbyDB/seg0/c2b1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2b1.dat

JavaDB Week5-3/derbyDB/seg0/c2c1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2c1.dat

JavaDB Week5-3/derbyDB/seg0/c2d0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2d0.dat

JavaDB Week5-3/derbyDB/seg0/c2e1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2e1.dat

JavaDB Week5-3/derbyDB/seg0/c2f0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c2f0.dat

JavaDB Week5-3/derbyDB/seg0/c300.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c300.dat

JavaDB Week5-3/derbyDB/seg0/c31.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c31.dat

JavaDB Week5-3/derbyDB/seg0/c311.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c311.dat

JavaDB Week5-3/derbyDB/seg0/c321.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c321.dat

JavaDB Week5-3/derbyDB/seg0/c331.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c331.dat

JavaDB Week5-3/derbyDB/seg0/c340.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c340.dat

JavaDB Week5-3/derbyDB/seg0/c351.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c351.dat

JavaDB Week5-3/derbyDB/seg0/c361.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c361.dat

JavaDB Week5-3/derbyDB/seg0/c371.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c371.dat

JavaDB Week5-3/derbyDB/seg0/c380.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c380.dat

JavaDB Week5-3/derbyDB/seg0/c391.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c391.dat

JavaDB Week5-3/derbyDB/seg0/c3a1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3a1.dat

JavaDB Week5-3/derbyDB/seg0/c3b1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3b1.dat

JavaDB Week5-3/derbyDB/seg0/c3c0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3c0.dat

JavaDB Week5-3/derbyDB/seg0/c3d1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3d1.dat

JavaDB Week5-3/derbyDB/seg0/c3e1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3e1.dat

JavaDB Week5-3/derbyDB/seg0/c3f1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c3f1.dat

JavaDB Week5-3/derbyDB/seg0/c400.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c400.dat

JavaDB Week5-3/derbyDB/seg0/c41.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c41.dat

JavaDB Week5-3/derbyDB/seg0/c411.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c411.dat

JavaDB Week5-3/derbyDB/seg0/c421.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c421.dat

JavaDB Week5-3/derbyDB/seg0/c430.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c430.dat

JavaDB Week5-3/derbyDB/seg0/c441.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c441.dat

JavaDB Week5-3/derbyDB/seg0/c451.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c451.dat

JavaDB Week5-3/derbyDB/seg0/c461.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c461.dat

JavaDB Week5-3/derbyDB/seg0/c51.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c51.dat

JavaDB Week5-3/derbyDB/seg0/c60.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c60.dat

JavaDB Week5-3/derbyDB/seg0/c71.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c71.dat

JavaDB Week5-3/derbyDB/seg0/c81.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c81.dat

JavaDB Week5-3/derbyDB/seg0/c90.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._c90.dat

JavaDB Week5-3/derbyDB/seg0/ca1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._ca1.dat

JavaDB Week5-3/derbyDB/seg0/cb1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._cb1.dat

JavaDB Week5-3/derbyDB/seg0/cc0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._cc0.dat

JavaDB Week5-3/derbyDB/seg0/cd1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._cd1.dat

JavaDB Week5-3/derbyDB/seg0/ce1.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._ce1.dat

JavaDB Week5-3/derbyDB/seg0/cf0.dat

__MACOSX/JavaDB Week5-3/derbyDB/seg0/._cf0.dat

__MACOSX/JavaDB Week5-3/derbyDB/._seg0

JavaDB Week5-3/derbyDB/service.properties

#C:\Users\Fayee\workspace\JavaDB Week5\derbyDB # ******************************************************************** # *** Please do NOT edit this file. *** # *** CHANGING THE CONTENT OF THIS FILE MAY CAUSE DATA CORRUPTION. *** # ******************************************************************** #Sun Jul 03 11:23:52 EAT 2016 SysschemasIndex2Identifier=225 SyscolumnsIdentifier=144 SysconglomeratesIndex1Identifier=49 SysconglomeratesIdentifier=32 SyscolumnsIndex2Identifier=177 SysschemasIndex1Identifier=209 SysconglomeratesIndex3Identifier=81 SystablesIndex2Identifier=129 SyscolumnsIndex1Identifier=161 derby.serviceProtocol=org.apache.derby.database.Database SysschemasIdentifier=192 derby.storage.propertiesId=16 SysconglomeratesIndex2Identifier=65 derby.serviceLocale=en_US SystablesIdentifier=96 SystablesIndex1Identifier=113

__MACOSX/JavaDB Week5-3/derbyDB/._service.properties

__MACOSX/JavaDB Week5-3/._derbyDB

JavaDB Week5-3/src/Animal.java

JavaDB Week5-3/src/Animal.java

/*
 * 
 * PRG / 421
 * July 4, 2016
 * =============================================================================================================
 * 
 * Animal class
 * 
 * =============================================================================================================
 */

class   Animal  
{  
     private   String  name ,  color ;   //  name and color properties of animals
     private   boolean  swim ,  vertebrate ;     //  swim and vertebrate properties
     public   Animal ( String  name ,   String  color ,   boolean  swim ,   boolean  vertebrate )  
     {  
         this . name  =  name ;  
         this . color  =  color ;  
         this . swim  =  swim ;
         this . vertebrate  =  vertebrate ;
     }
     //  Function to return name of animal
     public   String  getName ()  
     {  
         return  name ;  
     }  
     //  Function to set name of animal
     public   void  setName ( String  name )  
     {  
         this . name  =  name ;  
     }  
     //  Function to return color of animal
     public   String  getColor ()  
     {  
         return  color ;  
     }  
     //  Function to set color of animal
     public   void  setColor ( String  color )  
     {  
         this . color  =  color ;  
     }  
     //  Function to return true if animal can swim, otherwise, false
     public   boolean  getSwim ()  
     {  
         return  swim ;  
     }  
     //  Function to set whether or not an animal can swim
     public   void  setSwim ( boolean  swim )  
     {  
         this . swim  =  swim ;  
     }  
     //  Function to return whether or not an animal is vertebrate
     public   boolean  getVertebrate ()  
     {  
         return  vertebrate ;  
     }  
     //  Function to set whether or not an animal is vertebrate
     public   void  setVertebrate ( boolean  vertebrate )  
     {  
         this . vertebrate  =  vertebrate ;  
     }  
     //  Function to format the output - override the inbuilt toString() method
    @ Override   public   String  toString ()  
     {  
         return   "Animal [Name: "   +  name  +   ", Color: "   +  color  +   ", Can Swim: "   +  swim  +   ", Is Vertebrate :"   +  vertebrate  +   "]" ;  
     }  
}

__MACOSX/JavaDB Week5-3/src/._Animal.java

JavaDB Week5-3/src/AnimalDataAccessor.java

JavaDB Week5-3/src/AnimalDataAccessor.java

/*
 * 
 * PRG / 421
 * July 4, 2016
 * =============================================================================================================
 * 
 * Java program to demonstrate the use of JDBC. The program does the following:
 * 1.   Writes a list of animal and its characteristics to a database using JDBC.
 * 2.   Displays the characteristics of an animal when that animal is selected.
 * 
 * =============================================================================================================
 */
/*

   Derby - Class Animals JDBC app

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */

import  java . sql . Connection ;
import  java . sql . DriverManager ;
import  java . sql . PreparedStatement ;
import  java . sql . ResultSet ;
import  java . sql . SQLException ;
import  java . sql . Statement ;

import  java . util . ArrayList ;
import  java . util . Properties ;

public   class   AnimalDataAccessor   {
    
     /* derby client/server framework is embedded */
     private   String  framework  =   "embedded" ;
     /* Load the apache derby driver */
     private   String  driver  =   "org.apache.derby.jdbc.EmbeddedDriver" ;
     /* load the derby-jdbc protocol */
     private   String  protocol  =   "jdbc:derby:" ;

     public   static   void  main ( String []  args )  
     {
         new   AnimalDataAccessor (). go ( args );
         System . out . println ( "-------------------------------------------" );
         System . out . println ( "Animals JDBC Derby app completed." );
     }
    
     void  go ( String []  args ){
         /* parse the arguments to determine which framework is desired*/
        parseArguments ( args );
         System . out . println ( "Welcome to the animals JDBC Derby app\n==========================================" );      //  Title
         System . out . println ( "App started in "   +  framework  +   " mode." );

         /* Call function to load the JDBC driver */
        loadDriver ();
        
         /* Database connection object */
         Connection  conn  =   null ;
         /* PreparedStatement, Statement and ResultSet */
         ArrayList  statements  =   new   ArrayList ();
         PreparedStatement  stmnt  =   null ;
         Statement  s  =   null ;
         ResultSet  rs  =   null ;
        
         try
         {
             /* declare connection properties */
             Properties  props  =   new   Properties ();
             /* define user identified by password - optional */
            props . put ( "user" ,   "root" );
            props . put ( "password" ,   "" );
             /* specify the database to be used */
             String  dbName  =   "derbyDB" ;
             /* Initialize the database connection and create database */
            conn  =   DriverManager . getConnection ( protocol  +  dbName  +   "; create=true" ,  props );
             /* Success message */
             System . out . println ( "Connected to and created database "   +  dbName );

             /* set auto-commit to false to manually control transactions */
            conn . setAutoCommit ( false );

             /* create statement for which will be used to issue sql commands to the database. */
            s  =  conn . createStatement ();
            statements . add ( s );

             /* Create the animals table */
            s . execute ( "CREATE TABLE animals(id INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(20), color VARCHAR(10), isVertebrate BOOLEAN, canSwim BOOLEAN)" );
             /* Success message */
             System . out . println ( "Animals table successfully created." );
             /* initialize insert statement */
            stmnt  =  conn . prepareStatement ( "INSERT INTO animals(name, color, isVertebrate, canSwim) values (?, ?, ?, ?)" );
            statements . add ( stmnt );
             /* Dog is vertebrate and can swim */
            stmnt . setString ( 1 ,   "Dog" );
            stmnt . setString ( 2 ,   "Black" );
            stmnt . setString ( 3 ,   "true" );
            stmnt . setString ( 4 ,   "true" );
            stmnt . executeUpdate ();
             System . out . println ( "Dog has been added successfully." );
             /* Butterfly is vertebrate but cannot swim */
            stmnt . setString ( 1 ,   "Butterfly" );
            stmnt . setString ( 2 ,   "Indigo" );
            stmnt . setString ( 3 ,   "true" );
            stmnt . setString ( 4 ,   "false" );
            stmnt . executeUpdate ();
             System . out . println ( "Butterfly has been added successfully." );
             /* Fish is vertebrate and can swim */
            stmnt . setString ( 1 ,   "Fish" );
            stmnt . setString ( 2 ,   "Tan" );
            stmnt . setString ( 3 ,   "true" );
            stmnt . setString ( 4 ,   "true" );
            stmnt . executeUpdate ();
             System . out . println ( "Fish has been added successfully." );
             /* Snail is invertebrate and cannot swim */
            stmnt . setString ( 1 ,   "Snail" );
            stmnt . setString ( 2 ,   "Grey" );
            stmnt . setString ( 3 ,   "false" );
            stmnt . setString ( 4 ,   "false" );
            stmnt . executeUpdate ();
             System . out . println ( "Snail has been added successfully." );
             System . out . println ( "\n-------------------------------------------" );
             System . out . println ( "\n\nDisplaying available animals." );
             System . out . println ( "\n-------------------------------------------" );
             /* select all available rows from the database */
            rs  =  s . executeQuery ( "SELECT id, name, color, isVertebrate, canSwim  FROM animals ORDER BY id" );
             boolean  failure  =   false ;
            
             if   ( ! rs . next ())
             {
                failure  =   true ;
                reportFailure ( "No rows in ResultSet" );
             }
             System . out . println ( "Fetching animals..." );
             /* Variables to be used for display */
             int  id ;
             String  name ,  color ;
             boolean  swim ,  vertebrate ;
             /* Assign variables to the database column values */
            id  =  rs . getInt ( 1 );
            name  =  rs . getString ( 2 );
            color  =  rs . getString ( 3 );
            vertebrate  =  rs . getBoolean ( 4 );
            swim  =  rs . getBoolean ( 5 );
             /* Display the first record obtained */
             System . out . println ( "\n\nAnimal: " + id );
             System . out . print ( "-------------------------------------------\n" );
             System . out . println ( "Name: "   +  name );
             System . out . println ( "Color: "   +  color );
             System . out . println ( "Is Vertebrate: "   +  vertebrate );
             System . out . println ( "Can Swim: "   +  swim );
             System . out . print ( "-------------------------------------------\n" );
             /* Loop through all records then display data */
             while ( rs . next ())
             {
                id  =  rs . getInt ( 1 );
                name  =  rs . getString ( 2 );
                color  =  rs . getString ( 3 );
                vertebrate  =  rs . getBoolean ( 4 );
                swim  =  rs . getBoolean ( 5 );
                
                 System . out . println ( "\n\nAnimal: " + id );
                 System . out . print ( "-------------------------------------------\n" );
                 System . out . println ( "Name: "   +  name );
                 System . out . println ( "Color: "   +  color );
                 System . out . println ( "Is Vertebrate: "   +  vertebrate );
                 System . out . println ( "Can Swim: "   +  swim );
                 System . out . print ( "-------------------------------------------\n" );
             }
             if   ( ! failure )   {
                 System . out . println ( "Verified the rows." );
             }
             /* Drop the animals table */
            s . execute ( "DROP TABLE animals" );
             /* Success message */
             System . out . println ( "Animals table has been dropped." );

             /* Proceed to commit the transaction */
            conn . commit ();
             /* Success message */
             System . out . println ( "Transaction committed." );
             /*
             * In embedded mode, an application should shut down the database.
             * If the application fails to shut down the database,
             * Derby will not perform a checkpoint when the JVM shuts down.
             * This means that it will take longer to boot (connect to) the
             * database the next time, because Derby needs to perform a recovery
             * operation.
             *
             * It is also possible to shut down the Derby system/engine, which
             * automatically shuts down all booted databases.
             *
             * Explicitly shutting down the database or the Derby engine with
             * the connection URL is preferred. This style of shutdown will
             * always throw an SQLException.
             *
             * Not shutting down when in a client environment, see method
             * Javadoc.
             */

             if   ( framework . equals ( "embedded" ))
             {
                 try
                 {
                     // the shutdown=true attribute shuts down Derby
                     DriverManager . getConnection ( "jdbc:derby:;shutdown=true" );

                     // To shut down a specific database only, but keep the
                     // engine running (for example for connecting to other
                     // databases), specify a database in the connection URL:
                     //DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
                 }
                 catch   ( SQLException  se )
                 {
                     if   ((   ( se . getErrorCode ()   ==   50000 )
                             &&   ( "XJ015" . equals ( se . getSQLState ())   )))   {
                         // we got the expected exception
                         System . out . print ( "-------------------------------------------\n" );
                         System . out . println ( "Derby shut down normally" );
                         // Note that for single database shutdown, the expected
                         // SQL state is "08006", and the error code is 45000.
                     }   else   {
                         // if the error code or SQLState is different, we have
                         // an unexpected exception (shutdown failed)
                         System . err . println ( "Derby did not shut down normally" );
                        printSQLException ( se );
                     }
                 }
             }
         }
         catch   ( SQLException  sqle )
         {
            printSQLException ( sqle );
         }   finally   {
             // release all open resources to avoid unnecessary memory usage

             // ResultSet
             try   {
                 if   ( rs  !=   null )   {
                    rs . close ();
                    rs  =   null ;
                 }
             }   catch   ( SQLException  sqle )   {
                printSQLException ( sqle );
             }

             // Statements and PreparedStatements
             int  i  =   0 ;
             while   ( ! statements . isEmpty ())   {
                 // PreparedStatement extend Statement
                 Statement  st  =   ( Statement ) statements . remove ( i );
                 try   {
                     if   ( st  !=   null )   {
                        st . close ();
                        st  =   null ;
                     }
                 }   catch   ( SQLException  sqle )   {
                    printSQLException ( sqle );
                 }
             }

             //Connection
             try   {
                 if   ( conn  !=   null )   {
                    conn . close ();
                    conn  =   null ;
                 }
             }   catch   ( SQLException  sqle )   {
                printSQLException ( sqle );
             }
         }
     }
    
     /**
     * Loads the appropriate JDBC driver for this environment/framework. For
     * example, if we are in an embedded environment, we load Derby's
     * embedded Driver, <code>org.apache.derby.jdbc.EmbeddedDriver</code>.
     */
     private   void  loadDriver ()   {
         /*
         *  The JDBC driver is loaded by loading its class.
         *  If you are using JDBC 4.0 (Java SE 6) or newer, JDBC drivers may
         *  be automatically loaded, making this code optional.
         *
         *  In an embedded environment, this will also start up the Derby
         *  engine (though not any databases), since it is not already
         *  running. In a client environment, the Derby engine is being run
         *  by the network server framework.
         *
         *  In an embedded environment, any static Derby system properties
         *  must be set before loading the driver to take effect.
         */
         try   {
             Class . forName ( driver ). newInstance ();
             System . out . println ( "Loaded the appropriate driver" );
         }   catch   ( ClassNotFoundException  cnfe )   {
             System . err . println ( "\nUnable to load the JDBC driver "   +  driver );
             System . err . println ( "Please check your CLASSPATH." );
            cnfe . printStackTrace ( System . err );
         }   catch   ( InstantiationException  ie )   {
             System . err . println (
                         "\nUnable to instantiate the JDBC driver "   +  driver );
            ie . printStackTrace ( System . err );
         }   catch   ( IllegalAccessException  iae )   {
             System . err . println (
                         "\nNot allowed to access the JDBC driver "   +  driver );
            iae . printStackTrace ( System . err );
         }
     }
    
     /**
     * Reports a data verification failure to System.err with the given message.
     *
     *  @param  message A message describing what failed.
     */
     private   void  reportFailure ( String  message )   {
         System . err . println ( "\nData verification failed:" );
         System . err . println ( '\t'   +  message );
     }
    
     /**
     * Prints details of an SQLException chain to <code>System.err</code>.
     * Details included are SQL State, Error code, Exception message.
     *
     *  @param  e the SQLException from which to print details.
     */
     public   static   void  printSQLException ( SQLException  e )
     {
         // Unwraps the entire exception chain to unveil the real cause of the
         // Exception.
         while   ( !=   null )
         {
             System . err . println ( "\n----- SQLException -----" );
             System . err . println ( "  SQL State:  "   +  e . getSQLState ());
             System . err . println ( "  Error Code: "   +  e . getErrorCode ());
             System . err . println ( "  Message:    "   +  e . getMessage ());
             // for stack traces, refer to derby.log or uncomment this:
             //e.printStackTrace(System.err);
            e  =  e . getNextException ();
         }
     }
    
     /**
     * Parses the arguments given and sets the values of this class' instance
     * variables accordingly - that is which framework to use, the name of the
     * JDBC driver class, and which connection protocol protocol to use. The
     * protocol should be used as part of the JDBC URL when connecting to Derby.
     * <p>
     * If the argument is "embedded" or invalid, this method will not change
     * anything, meaning that the default values will be used.</p>
     * <p>
     *  @param  args JDBC connection framework, either "embedded", "derbyclient".
     * Only the first argument will be considered, the rest will be ignored.
     */
     private   void  parseArguments ( String []  args )
     {
         if   ( args . length  >   0 )   {
             if   ( args [ 0 ]. equalsIgnoreCase ( "derbyclient" ))
             {
                framework  =   "derbyclient" ;
                driver  =   "org.apache.derby.jdbc.ClientDriver" ;
                protocol  =   "jdbc:derby://localhost:3306/" ;
             }
         }
     }

}

__MACOSX/JavaDB Week5-3/src/._AnimalDataAccessor.java

__MACOSX/JavaDB Week5-3/._src

__MACOSX/._JavaDB Week5-3