myapp.java

来自「Java的面向对象数据库系统的源代码」· Java 代码 · 共 60 行

JAVA
60
字号
import org.ozoneDB.*;public class MyApp {        private static ExternalDatabase	db;    public static void main( String[] args ) throws Exception {        if (args.length == 0) {            System.out.println( "usage: ojvm MyApp create|delete|print" );            System.exit( 1 );        }                // create and open a new database connection        db = ExternalDatabase.openDatabase( "ozonedb:remote://localhost:3333" );        System.out.println( "Connected ..." );                db.reloadClasses();                if (args[0].equals( "create" )) {            createCar();        } else if (args[0].equals( "delete" )) {            deleteCar();        } else {            printCar();        }                db.close();    }    public static void createCar() throws Exception {        // create a new Car object with the name "my_first_car"        // the return value is Car_proxy, which implements the Car-interface        Car car = (Car)(db.createObject( CarImpl.class.getName(), 0,                "my_first_car" ));                car.setName( "gottfried" );        car.setYearOfConst( 1957 );    }    public static void printCar() throws Exception {        Car car = (Car)(db.objectForName( "my_first_car" ));        if (car != null) {            System.out.println( "The car " + car.name() + " is "                     + car.age() + " years old." );        } else {            System.out.println( "Object my_first_car not found." );        }    }        public static void deleteCar() throws Exception {        Car car = (Car)(db.objectForName( "my_first_car" ));        if (car != null) {            db.deleteObject( car );        } else {            System.out.println( "Object my_first_car not found." );        }    }}

⌨️ 快捷键说明

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