Some Java program examples using the JDBC/CQL interface

Language used :
JAVA 1.1.x or older and the InterDB driver (sets of JDBC classes)

Written by  :
Philippe Thiran

Copyright Note :
(C) InterDB Project, DB-MAIN programme, University of Namur, Belgium, 1999

Last modification :
August 1999



 CQL Selection

Note:
The conceptual schema comprises only one entity type: Customer. Customer has three attributes: name, surname and address that is compound. The generated entity-objects are the following (note that these files are generated by a Voyager program):

import java.io.*; // because of Serializable

File Customer.java

public class Customer implements Serializable // Because this is a remote object
{
  public String name;
  public String surname;
  public Address address;
}

File Address.java

import java.io.*;

class Address implements Serializable // Because this is a remote object

 {
  public int zip;
  public String city;
 };

Note:
Here is the main program:

File test.java

class test
{
 public static void main (String args[])
 {
   try{
       Connection con =DriverManager.getConnection("maverick.info.fundp.ac.be/ServerCQL", "test", "test");
       Statement stmt = con.createStatement();
       ResultSet rs;
       rs=stmt.executeQuery("SELECT C.*, C.address from Customer C");

       if  (rs.first())
            {
                Customer C = (Customer)rs.getObject("C.*"); //getObject = getAll
                System.err.println("Customer.name."+C.name);
                System.err.println("Customer.name."+C.surname);

                // Two ways to get the customer's address:

                Address A1 = (Address)rs.getObject("C.address");
                System.err.println("Address.code."+A1.zip);

                Address A2 = C.address;
                System.err.println("Address.city."+A2.city);
           }

       con.close();

   }catch (CQLException e) {System.err.println("Error:"+e);}

 }
}


Philippe Thiran - August 1998