Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 307,138 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,817 people online right now. Registration is fast and FREE... Join Now!




Inserting Java objects into an HSQLdb database

 
Reply to this topicStart new topic

> Inserting Java objects into an HSQLdb database

Rating  5
pbl
Group Icon



post 1 Jul, 2009 - 04:49 PM
Post #1


Many the question has been asked in the forum:
How to put a Java object into a DataBase ?

How does serialization been performed ? BLOB and CLOB ?

Here an example using HSQLdb. Why HSQLdb ? Because first, it is the database I use :-)
But also because HSQLdb, even if not as well known as MySQL is 100% Java based.
You can store an remove Java objects from HSQLdb as long as they implement Serializable.

If your BD will always be accessed by Java there is no reason not to use HSQLdb.
It can be downloaded from here

http://www.hsqldb.org/
the only thing you will download is a single .jar file:
hsqldb.jar

HSQLdb can be used in 2 modes:
- in StandAlone mode
- regular ClientServer mode

in StandAlone mode, the HSQLdb driver is imbedded in your application. So you cannot share the DataBase
with another application but if your application is stand alone and you are the only
one using the database that is the best way to go.

Both mode will be explained.
I tried to make a simple example. A database with 3 tables each of them will hold
instance of a simple Java object.

The first table: FirstNameTable which has 3 columns:
- The object FirstName
- The table unique Id
- The FirstName as a String (for uniqueness)

The second table: LastNameTable which has 3 columns:
- The object LastName
- The table unique Id
- The FirstName as a String (for uniqueness)

The third table: FullNameTable which has 4 columns:
- The object FullName
- The table unique Id
- A foreign key on a row of FirtNameTable
- A foreign key on a row of LastNameTable

The tables unique Id are very usefull and each object in the DB will contain its unique Id.
To share a lot of method for SQL access many of them will use GetSetId interface.
This inetrafce should be implement by all objects going in the DB

CODE

/*
** All the objects stored in the DB must implements these 2 methods
** that allows to store/retreive the DB unique Id within a table
*/
public interface GetSetId {

    // to get the BD unique Id
    public int getId();
    // to set it in an object after reading the object from the DB
    public void setId(int id);
}


OK now. The FirstName and LastName objects are just a clone of each of other.
So I made a class GenericName from where FirstName and LastName derive.

CODE

/*
* * This class will be overload by both FirstName and LastName
* * It must implement Serializable
*/
public class GenericName implements Serializable, GetSetId {

    // use for serialization
    private static final long serialVersionUID = 200906292210L;
    
    // the actual only element stored in the DB
    private String name;
    // the unique Id whitin the table in the DB that will be generate by the DB
    // this element is not stored in the DB
    transient private int id;
    
    // constructor that receives the Name as parameter
    GenericName(String name) {
        setName(name);
    }
    
    // getters and setters
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    String getName() {
        return name;
    }
    void setName(String name) {
        this.name = name;
    }
    // displayed name    
    public String toString() {
        return "[" + id + "]" + " " + name;
    }

}


Note that the int id variable is transient. It will not be stored in the serialized
object that will be store in the DataBase. One of the reason for that is that it is the
database that will generate that number when you will store an elemnt in the DB and
you cannot know it before storing the object in the database.

All serialized class must have a private static final long serialVersionUID.

private static final long serialVersionUID = 200906292210L;

I usually put the date where I wrote the class the first time in format YYYMMDDHHMM
this garanties me uniqueness as I do not usually write more than one class per minute :-)

So now how does my FirstName and LastName class look like:

CODE

import java.io.Serializable;

/**
* This class define is the object FirstName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class FirstName extends GenericName implements Serializable {

    // This a unique number that will be used during serialization
    private static final long serialVersionUID = 200906271625L;

    // Constructor that calls the father GenericName
    FirstName(String name) {
        super(name);
    }



CODE

import java.io.Serializable;

/**
* This class define is the object LastName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class LastName extends GenericName implements Serializable {

    // This a unique number that will be used during serialization
    private static final long serialVersionUID = 200906271600L;

    // Constructor that calls the father GenericName
    LastName(String name) {
        super(name);
    }


And the FullName class which has a FirstName a LastName and an age as integer
CODE

import java.io.Serializable;

/**
* This class define is the object FullName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class FullName implements Serializable, GetSetId {

    // This a unuique number that will be used during serialization
    private static final long serialVersionUID = 200906271650L;

    // the Id of both FirstName and LastName
    private int lastNameId, firstNameId;
    // the age of the person
    private int age;
    
    // all the other variables are transient, they are not stored in the database
    // my own unique id in the DB
    private transient int id;
    
    // The FirstName and LastName objects (these are transient because not stored in the DB)
    private transient LastName lastName;
    private transient FirstName firstName;
    
    // Constructor that calls the father
    FullName(FirstName firstName, LastName lastName, int age) {
        this.lastName = lastName;
        this.firstName = firstName;
        lastNameId = lastName.getId();
        firstNameId = firstName.getId();
        this.age = age;
    }

    public String toString() {
        return lastName.getName() + ", " + firstName.getName() + "  " + age + " years old";
    }

    public int getId() {
        return id;
    }
    // this one is called when read from the DB
    // we have to fill our transient fields
    public void setId(int id) {
        this.id = id;
        firstName = FirstNameTable.getInstance().getById(firstNameId);
        lastName = LastNameTable.getInstance().getById(lastNameId);
    }

    public final int getLastNameId() {
        return lastNameId;
    }

    public final void setLastNameId(int lastNameId) {
        this.lastNameId = lastNameId;
    }

    public final int getFirstNameId() {
        return firstNameId;
    }

    public final void setFirstNameId(int firstNameId) {
        this.firstNameId = firstNameId;
    }
    
    public int getAge() {
        return age;
    }


Don't worry for now on how the firstName and lastName are set in method setId()
we'll see that later. These code of these 3 classes is not all showed yet
but don't worry complete code will be showed later.

OK now we have 3 classes to handle the 3 tables in the DataBase.
We have FirstNameTable, LastNameTable and FullNameTable.
Many methods are common to these 3 classes and are defined in DbTable.
The 3 classes derives from DbTable

CODE

package ca.pblinc.hsqldb;

import java.sql.*;
import java.util.ArrayList;

/*
* All tables classes must extends this class. It conatins
* - the DB Connection object
* - the common PreparedStatement
* - common methods
* Note: we assume DB Username is "sa" and password is ""
*/
public class DbTable {
    // path for standalone mode
    private static final String dbPathStandAlone = "jdbc:hsqldb:file:";
    // path for server mode
    private static final String dbPathWithServer = "jdbc:hsqldb:hsql://";

    // the unique Connection object used and shared by all tables
    static Connection con;
    // a unique instance of this
    static DbTable instance;
    // the common PreparedStatement
    PreparedStatement prstInsert, prstUpdate, prstDelete, prstGetById, prstSelectAll;
    // to get the last Id of an element inserted in the Bd
    private static PreparedStatement prstGetLastId;

    // there are 2 constructor one for Standlone mode and one for server mode

    // In process mode receives the name of the DB filename
    DbTable(String dbName) {
        System.out.println("Constructor of DbTable in StandAlone mode");
        // load HSQLdb driver
        loadDriver();
        // try to connect in standalone mode
        try {
            con = DriverManager.getConnection(dbPathStandAlone + dbName, "sa", "");
            System.out.println("Correctly connected in StandAlone mode.");
        }
        catch (SQLException e) {
            int code = e.getErrorCode();
            System.out.println("getConnection failed: " + code + " " + e);
            throw new IllegalStateException("Cannot connect to DB in StandAlone mode.");
        }
        // create tables object
        createTables();
    }

    // Server mode receives pseudo name of the bd offerered by the server and server IP address
    DbTable(String dbName, String host) {
        System.out.println("Consructor of DBTable in Server Mode");
        //bdName load HSQLdb driver
        loadDriver();
        // try to connect to the server
        try {
            con = DriverManager.getConnection(dbPathWithServer + host + "/" + dbName, "sa", "");
            System.out.println("Correctly connected in to the server.");
        }
        catch (SQLException e) {
            int code = e.getErrorCode();
            System.out.println("getConnection failed: " + code + " " + e);
            throw new IllegalStateException("Cannot connect to DB server.");
        }
        // create tables object
        createTables();
    }

    // an empty constructor for the ones that extend me
    DbTable() {        
    }

    // use to load the HSQLdb driver use by both connection type
    private void loadDriver() {
        instance = this;
        try {
            Class.forName("org.hsqldb.jdbcDriver"); //.newInstance();
            System.out.println("HSQLdb driver correctly loaded.");
        }
        catch (Exception e) {
            System.out.println("Problem loading JDBC driver: " + e);
            throw new IllegalStateException("HSQLDB driver couldn't be loadded.");
        }
    }

    // common part that are executed both in StandAlone mode and in Server mode
    // it creates an instance of all xxxxTable so object can access them
    void createTables() {
        // build the PrepareStement to get the Id of the last element inserted in the Db
        // only one for all tables so it is a static variable
        try {
            prstGetLastId = con.prepareStatement("call identity()");
        }
        catch (SQLException e) {
            System.out.println("Problem creating prstGetId PreparedStatement.");
            throw new IllegalStateException("Problem creating prstGetId PreparedStatement.");
        }
        // creates all other tables object
        new FirstNameTable();
        new LastNameTable();
        new FullNameTable();
    }

    /** Share method to get a resultSet from an SQL string */
    protected ResultSet queryExecute(String sqlString) {
        try {
            PreparedStatement stmt = con.prepareStatement(sqlString);
            return queryExecute(stmt);
        }
        catch (SQLException e) {
            int code = e.getErrorCode();
            System.out.println("queryExecute building prepStatement " + sqlString + " returns " + code + " "+ e);
            return null;
        }
    }
    /** General method to execute a query using a PreparedStatement */
    protected ResultSet queryExecute(PreparedStatement stmt) {
        System.out.println("DbTable.queryExecute(" + stmt + ")");
        try {
            ResultSet result = stmt.executeQuery();
            return result;      
        }
        catch (SQLException e) {
            System.out.println("queryExecute: " + stmt + " returns " + e);
            return null;        
        }                  
    }

    /** General method to do a statement.execute from a String. Returns the number of rows affected  */
    int statementExecute(String sql)
    {
        int nb = -1;
        try {
            PreparedStatement stmt = con.prepareStatement(sql);        // on prepare le statement
            nb = statementExecute(stmt);
        }
        catch (SQLException e) {
            System.out.println("StatementExecute building prepStatement for " + sql + " returns: " + e);
        }
        System.out.println("statementExecute(" + sql + ") returns " + nb);
        return nb;
    }

    /** General method to do a statementExecute from a PreparedStatement. Returns the number of rows affected */
    int statementExecute(PreparedStatement stmt)
    {
        int nb = -1;
        try {
            nb = stmt.executeUpdate();                        // la commande passee en parametre
        }
        catch (SQLException e) {
            int code = e.getErrorCode();
            System.out.println("statementExecute: " + stmt);
            System.out.println("status: " + code + ">> "+ e);
        }
        return nb;
    }

    /*
     * returns the row count from a table whose name is passed as parameter
     * returns -1 if the table does not exist
     */
    int getCount(String tableName) {
        int nb = -1;
        String sql = "SELECT COUNT(*) FROM " + tableName + ";";

        // call our queryExcute method
        ResultSet rs = queryExecute(sql);
        // if ResultSet is nulll returns -1
        if(rs == null) {
            System.out.println("GetCount() on " + tableName + " returns " + nb);
            return nb;
        }
        // fetch rows count
        try {
            rs.next();
            nb = rs.getInt(1);
            rs.close();
        }
        catch (SQLException e) {
            throw new IllegalStateException("DbTable.getCount() rs.getNext() or rs.getInt Exception: " + e);        
        }

        System.out.println("GetCount() on " + tableName + " returns " + nb);
        return nb;
    }

    /** Returns the Id of the last element inserted into the DB */
    int getIdentity() {
        ResultSet rs = queryExecute(prstGetLastId);
        try {
            rs.next();
            int id = rs.getInt(1);
            rs.close();
            return id;
        }
        catch (SQLException e) {
            throw new IllegalStateException("Something wrong with getIdentity().");
        }
    }

    // returns an ArrayList of all the elements in a table. All our objects implements GetSetId.
    protected ArrayList<GetSetId> sqlSelectAll() {
        ArrayList<GetSetId> al = new ArrayList<GetSetId>();
        ResultSet rs = queryExecute(prstSelectAll);
        try {
            // scan the ResultSet to extract all FirstName
            while(rs.next()) {
                GetSetId obj = (GetSetId) rs.getObject(1);    // get next object in column 1
                int id = rs.getInt(2);                        // get its id in column 2
                obj.setId(id);                                // set the object Id into the transient instance variable
                al.add(obj);                                // added to the array list
            }
            // free the resources of the working set
            rs.close();
        }
        catch(SQLException e) {
            System.out.println("DbTable.selectAll() exception: " + e + " for " + prstSelectAll);
        }

        return al;
    }

    // delete an object from the database
    boolean sqlDelete(GetSetId obj) {
        try {
            prstDelete.setInt(1, obj.getId());
            return statementExecute(prstDelete) > 0;
        }
        catch(SQLException e) {
            System.out.println("DbTable.deleteById exception: " + e);
        }
        // obviously didn't work
        return false;
    }
    
    /*
     * returns a row by its Id. The classes that call this method will cast the GetSetId object to
     * the object they served (FirstName, LastName or FullName)
     */
    GetSetId sqlGetById(int id) {
        try {
            prstGetById.setInt(1, id);
            ResultSet rs = queryExecute(prstGetById);
            if(rs == null)
                return null;
            if(!rs.next())
                return null;
            GetSetId obj = (GetSetId) rs.getObject(1);    // get next object in column 1
            obj.setId(id);
            return obj;
        }
        catch(SQLException e) {
            System.out.println("sqlGetById exception for Id: " + id + " Error: " + e);
        }
        return null;
    }
    // returns the Connection object to the DB
    static DbTable getInstance() {
        return instance;
    }
}

Note that this class contains a lot of System.out.println() that can be removed when
you'll understand how all the stuff works.

OK let see now how the 3 other classes extend that DbTable

Now that you know that objects FirstNameTable, LastNameTable and FullNameTable we can
complete the code of their respective FirstName, LastName and FullName

CODE

import java.io.Serializable;

/**
* This class define is the object FirstName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class FirstName extends GenericName implements Serializable {

    // This a unique number that will be used during serialization
    private static final long serialVersionUID = 200906271625L;

    // Constructor that calls the father GenericName
    FirstName(String name) {
        super(name);
    }
    
    // insert that object into the DB
    boolean sqlInsert() {
        // get the singleton of my table
        FirstNameTable table = FirstNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlInsert(this);
    }
    
    // delete this object from the db
    boolean sqlDelete() {
        // get the singleton of my table
        FirstNameTable table = FirstNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlDelete(this);
    }
    
    // update this object
    boolean sqlUpdate() {
        // get the singleton of my table
        FirstNameTable table = FirstNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlUpdate(this);        
    }
}

CODE

import java.io.Serializable;

/**
* This class define is the object LastName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class LastName extends GenericName implements Serializable {

    // This a unique number that will be used during serialization
    private static final long serialVersionUID = 200906271600L;

    // Constructor that calls the father GenericName
    LastName(String name) {
        super(name);
    }

    // insert that object into the DB
    boolean sqlInsert() {
        // get the singleton of my table
        LastNameTable table = LastNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlInsert(this);
    }
    
    // delete this object from the db
    boolean sqlDelete() {
        // get the singleton of my table
        LastNameTable table = LastNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlDelete(this);
    }
    
    // update this object
    boolean sqlUpdate() {
        // get the singleton of my table
        LastNameTable table = LastNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlUpdate(this);        
    }
}

CODE

import java.io.Serializable;

/**
* This class define is the object FullName that will be stored in the DB
* An object that wants to be stored in a DB needs to implement Serializable
*/
public class FullName implements Serializable, GetSetId {

    // This a unuique number that will be used during serialization
    private static final long serialVersionUID = 200906271650L;

    // the Id of both FirstName and LastName
    private int lastNameId, firstNameId;
    // the age of the person
    private int age;
    
    // all the other variables are transient, they are not stored in the database
    // my own unique id in the DB
    private transient int id;
    
    // The FirstName and LastName objects (these are transient because not stored in the DB)
    private transient LastName lastName;
    private transient FirstName firstName;
    
    // Constructor that calls the father
    FullName(FirstName firstName, LastName lastName, int age) {
        this.lastName = lastName;
        this.firstName = firstName;
        lastNameId = lastName.getId();
        firstNameId = firstName.getId();
        this.age = age;
    }

    public String toString() {
        return lastName.getName() + ", " + firstName.getName() + "  " + age + " years old";
    }

    public int getId() {
        return id;
    }
    // this one is called when read from the DB
    // we have to fill our transient fields
    public void setId(int id) {
        this.id = id;
        firstName = FirstNameTable.getInstance().getById(firstNameId);
        lastName = LastNameTable.getInstance().getById(lastNameId);
    }

    public final int getLastNameId() {
        return lastNameId;
    }

    public final void setLastNameId(int lastNameId) {
        this.lastNameId = lastNameId;
    }

    public final int getFirstNameId() {
        return firstNameId;
    }

    public final void setFirstNameId(int firstNameId) {
        this.firstNameId = firstNameId;
    }
    
    public int getAge() {
        return age;
    }
    // insert that object into the DB
    boolean sqlInsert() {
        // get the singleton of my table
        FullNameTable table = FullNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlInsert(this);
    }

    // delete this object from the db
    boolean sqlDelete() {
        // get the singleton of my table
        FullNameTable table = FullNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlDelete(this);
    }
    
    // update this object
    boolean sqlUpdate() {
        // get the singleton of my table
        FullNameTable table = FullNameTable.getInstance();
        // calls the method to insert a FirstName
        return table.sqlUpdate(this);        
    }

}


OK now let us look at the 3 classes that extend DbTable
When each of these xxxTable object constructor is called, if the Table does not exist
in the database it is created.
Note: for testing purpose: if the table is created there is code to add some
predefined entries in the database.
More than that, the FirstNameTable has code to test the Update and Delete transaction.
The FullNameTable, when first created, generates randomly choosen FullName from FirstName
and LastName with also a randomly selected age.
If the table already exist, a list of all the elements in the table is showed.

CODE

import java.sql.*;
import java.util.*;

// handles the FirstNameTable
public class FirstNameTable extends DbTable{

    // this table is a Singleton
    private static FirstNameTable instance;
    // predefined FirstName to be used if DB is empty
    private static final String[] fName = {"paul", "benoit", "john", "neo", "cabbage", "honey", "mike"};
    // Table name and is create statement
    private static final String tableName = "FirstNameTable";
    // by default HSQLdb creates in memory table we need the keyword "Cached Table" to make it on disk
    private static final String createTable =
        "Create Cached Table " + tableName + " (" +
        "Obj OBJECT, " +                            // the Object implementing GetSetId()
        "Id INTEGER IDENTITY PRIMARY KEY, " +         // unique Id within that table
        "Name VARCHAR(1024) NOT NULL, " +            // the name unique (not case sensitive) within the table
        "UNIQUE (Id), " +
        "UNIQUE (Name)" +
        ");";
    
    /*
     * This class handles the SQL requests to the FirstNameTable
     */
    FirstNameTable() {
        instance = this;
        // a flag to inform us if the table existed or not
        // if it didn't exist we will populate it
        boolean tableExisted = true;
        // we check if the table exist if not we create it
        if(getCount() == -1) {
            // flag table creation
            tableExisted = false;
            statementExecute(createTable);            // lets create it
            // I hate tableId starting at 0 (personal preference so I set the Id to start at 1)
             statementExecute("ALTER TABLE " + tableName + " ALTER COLUMN Id RESTART WITH 1;");                    
         }
        
        // we create our PreparedStatements
        try {
            prstInsert = con.prepareStatement("INSERT INTO " + tableName + " (Obj, Id, Name) VALUES (?, ?, ?)");
            prstUpdate = con.prepareStatement("UPDATE " + tableName + " SET Name = ?, Obj = ? WHERE Id = ?;");
            prstDelete = con.prepareStatement("DELETE FROM " + tableName + " WHERE Id = ?;");
            prstGetById = con.prepareStatement("SELECT Obj FROM " + tableName + " WHERE Id = ?;");
            prstSelectAll = con.prepareStatement("SELECT Obj, Id FROM " + tableName + " ORDER BY Name;");
        }
        catch(SQLException e) {
            System.out.println("Problem creating PreparedStatement for " + tableName + ".");
            throw new IllegalStateException("Problem creating PreparedStatement for " + tableName + ".");
        }
        
        // now if the table didn't exist we fill it with our predefined elements
        if(!tableExisted) {
            // loopt throught our predifed name to initialize the table
            for(int i = 0; i < fName.length; i++) {
                // create FirtName object
                FirstName fn = new FirstName(fName[i]);
                // insert it into DB
                fn.sqlInsert();
            }            
            // list all the element in the BD
            ArrayList<GetSetId> al = sqlSelectAll();
            System.out.println("List if the " + al.size() + " elements in table " + tableName + " order by Name.");
            for(int i = 0; i < al.size(); i++)
                System.out.println((FirstName) al.get(i));

            // update one element to test the update transaction
            FirstName fn = (FirstName) al.get(1);
            // appends "xxx" to the name (this is just to test the Update transaction)
            fn.setName(fn.getName() + "xxx");
            fn.sqlUpdate();
            
            al = sqlSelectAll();
            System.out.println("List if the " + al.size() + " elements in table " + tableName + " after Update.");
            for(int i = 0; i < al.size(); i++)
                System.out.println((FirstName) al.get(i));
            
            // we delete the second of them to test the delete transaction
            ((FirstName) al.get(1)).sqlDelete();
            // relist the contents
            al = sqlSelectAll();
            System.out.println("List if the " + al.size() + " elements in table " + tableName + " after delete.");
            for(int i = 0; i < al.size(); i++)
                System.out.println((FirstName) al.get(i));

        }
        else {  // Table already exist
            // list all the element in the BD
            ArrayList<GetSetId> al = sqlSelectAll();
            System.out.println("List if the " + al.size() + " elements in table " + tableName + " order by Name.");
            for(int i = 0; i < al.size(); i++)
                System.out.println((FirstName) al.get(i));
        }
    }
        
    // to return the single instance of this class
    static FirstNameTable getInstance() {
        return instance;
    }
    
    // to insert a new FirstName
    boolean sqlInsert(FirstName fn) {
        boolean status = false;
        try {
            // put the serialized  object by itself
            prstInsert.setObject(1, fn, Types.JAVA_OBJECT);
            // the uniqueId we do not know it yet so we set it to null
            prstInsert.setNull(2, Types.INTEGER);
            // we put the name bacause we want it unique case independant
            prstInsert.setString(3, fn.getName().toUpperCase());
            // perform the insert statement
            int nbChanged = statementExecute(prstInsert);
            status = nbChanged > 0;
            System.out.println("Statement execute " + prstInsert + " rows affected " + nbChanged + " status " + status);
        }
        catch(SQLException e) {
            System.out.println("FirstNameTable sqlInsert() exception: " + e);
        }
        return status;
    }
    
    // to insert a new FirstName
    boolean sqlUpdate(FirstName fn) {
        boolean status = false;
        try {
            // we put the name bacause we want it unique case independant
            prstUpdate.setString(1, fn.getName().toUpperCase());
            // put the serialized  object by itself
            prstUpdate.setObject(2, fn, Types.JAVA_OBJECT);
            // the uniqueId
            prstUpdate.setInt(3, fn.getId());
            // perform the insert statement
            int nbChanged = statementExecute(prstUpdate);
            status = nbChanged > 0;
            System.out.println("Statement execute " + prstUpdate + " rows affected " + nbChanged + " status " + status);
        }
        catch(SQLException e) {
            System.out.println("FirstNameTable sqlUpdate() exception: " + e);
        }
        return status;
    }
    
    /** Returns the number of entries in the table */
    int getCount() {
        return getCount(tableName);
    }
    
    /** Returns a FirstName object by Id
     *  we call the standard method that returns a GetSetId and cast it */
    FirstName getById(int id) {
        return (FirstName) sqlGetById(id);
    }

}

CODE

import java.sql.*;
import java.util.*;

// handles the FirstNameTable
public class LastNameTable extends DbTable{

    // this table is a Singleton
    private static LastNameTable instance;
    // predefined FirstName to be used if DB is empty
    private static final String[] fName = {"larochelle", "shyhawk33", "tiffa", "fooley", "mastermind", "trigga"};
    // Table name and is create statement
    private static final String tableName = "LastNameTable";
    // by default HSQLdb creates in memory table we need the keyword "Cached Table" to make it on disk
    private static final String createTable =
        "Create Cached Table " + tableName + " (" +
        "Obj OBJECT, " +                            // the Object implementing GetSetId()
        "Id INTEGER IDENTITY PRIMARY KEY, " +         // unique Id within that table
        "Name VARCHAR(1024) NOT NULL, " +            // the name unique (not case sensitive) within the table
        "UNIQUE (Id), " +
        "UNIQUE (Name)" +
        ");";
    
    /*
     * This class handles the SQL requests to the FirstNameTable
     */
    LastNameTable() {
        instance = this;
        // a flag to inform us if the table existed or not
        // if it didn't exist we will populate it
        boolean tableExisted = true;
        // we check if the table exist if not we c

This post has been edited by pbl: 1 Jul, 2009 - 06:01 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

pbl
Group Icon



post 1 Jul, 2009 - 07:20 PM
Post #2
Now if you cut & paste all the classes and run the TestStandAlone class that is what you should see

CODE

Constructor of DbTable in StandAlone mode
HSQLdb driver correctly loaded.
Correctly connected in StandAlone mode.
queryExecute building prepStatement SELECT COUNT(*) FROM FirstNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM FirstNameTable;]
GetCount() on FirstNameTable returns -1
statementExecute(Create Cached Table FirstNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, Name VARCHAR(1024) NOT NULL, UNIQUE (Id), UNIQUE (Name));) returns 0
statementExecute(ALTER TABLE FirstNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1989f84], [null], [PAUL]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1238bd2], [null], [BENOIT]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1198891], [null], [JOHN]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@17725c4], [null], [NEO]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@a761fe], [null], [CABBAGE]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@f0c0d3], [null], [HONEY]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@bb7759[sql=[INSERT INTO FirstNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@12cc95d], [null], [MIKE]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 7 elements in table FirstNameTable order by Name.
[2] benoit
[5] cabbage
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1df280b[sql=[UPDATE FirstNameTable SET Name = ?, Obj = ? WHERE Id = ?;], parameters=[[CABBAGEXXX], [org.hsqldb.types.JavaObject@1be0f0a], [5]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 7 elements in table FirstNameTable after Update.
[2] benoit
[5] cabbagexxx
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
List if the 6 elements in table FirstNameTable after delete.
[2] benoit
[6] honey
[3] john
[7] mike
[4] neo
[1] paul
queryExecute building prepStatement SELECT COUNT(*) FROM LastNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM LastNameTable;]
GetCount() on LastNameTable returns -1
statementExecute(Create Cached Table LastNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, Name VARCHAR(1024) NOT NULL, UNIQUE (Id), UNIQUE (Name));) returns 0
statementExecute(ALTER TABLE LastNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1c86be5], [null], [LAROCHELLE]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@162dbb6], [null], [SHYHAWK33]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@2ba11b], [null], [TIFFA]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@8c1dd9], [null], [FOOLEY]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1462851], [null], [MASTERMIND]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@1f8c6df[sql=[INSERT INTO LastNameTable (Obj, Id, Name) VALUES (?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@4ac00c], [null], [TRIGGA]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1865b28[sql=[SELECT Obj, Id FROM LastNameTable ORDER BY Name;]])
List if the 6 elements in table LastNameTable order by Name.
[4] fooley
[1] larochelle
[5] mastermind
[2] shyhawk33
[3] tiffa
[6] trigga
queryExecute building prepStatement SELECT COUNT(*) FROM FullNameTable; returns -22 java.sql.SQLException: Table not found in statement [SELECT COUNT(*) FROM FullNameTable;]
GetCount() on FullNameTable returns -1
statementExecute(Create Cached Table FullNameTable (Obj OBJECT, Id INTEGER IDENTITY PRIMARY KEY, FirstNameId INTEGER NOT NULL, LastNameId INTEGER NOT NULL, FOREIGN KEY (FirstNameId) REFERENCES FirstNameTable (Id), FOREIGN KEY (LastNameId) REFERENCES LastNameTable (Id), UNIQUE (Id));) returns 0
statementExecute(ALTER TABLE FullNameTable ALTER COLUMN Id RESTART WITH 1;) returns 0
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@157fb52[sql=[SELECT Obj, Id FROM FirstNameTable ORDER BY Name;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1865b28[sql=[SELECT Obj, Id FROM LastNameTable ORDER BY Name;]])
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@110fe28], [null], [7], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1d64c37], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@12be1bd], [null], [1], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1a5f739], [null], [1], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@e6ff0d], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1e97f9f], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@288051], [null], [4], [2]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@ee7a14], [null], [3], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@6cb8], [null], [3], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@d81784], [null], [4], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@142a80d], [null], [6], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@139b78e], [null], [7], [4]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@d6a05e], [null], [6], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@9df6f1], [null], [2], [1]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@b8bef7], [null], [4], [5]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@c1f10e], [null], [7], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@4a6cbf], [null], [2], [4]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1a99561], [null], [7], [6]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@1b000e7], [null], [3], [3]]] rows affected 1 status true
Statement execute org.hsqldb.jdbc.jdbcPreparedStatement@ec4a87[sql=[INSERT INTO FullNameTable (Obj, Id, FirstNameId, LastNameId) VALUES (?, ?, ?, ?)], parameters=[[org.hsqldb.types.JavaObject@b01d43], [null], [7], [1]]] rows affected 1 status true
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@513cf0[sql=[SELECT Obj, Id FROM FullNameTable;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
List if the 20 elements in table FullNameTable.
tiffa, mike  26 years old
tiffa, neo  31 years old
mastermind, paul  43 years old
tiffa, paul  25 years old
tiffa, neo  28 years old
tiffa, neo  23 years old
shyhawk33, neo  42 years old
tiffa, john  49 years old
mastermind, john  32 years old
tiffa, neo  34 years old
tiffa, honey  21 years old
fooley, mike  49 years old
trigga, honey  38 years old
larochelle, benoit  27 years old
mastermind, neo  26 years old
trigga, mike  25 years old
fooley, benoit  39 years old
trigga, mike  47 years old
tiffa, john  45 years old
larochelle, mike  39 years old
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@513cf0[sql=[SELECT Obj, Id FROM FullNameTable;]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[5]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[2]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[4]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[6]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[3]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@177b3cd[sql=[SELECT Obj FROM FirstNameTable WHERE Id = ?;], parameters=[[7]]])
DbTable.queryExecute(org.hsqldb.jdbc.jdbcPreparedStatement@1bd7848[sql=[SELECT Obj FROM LastNameTable WHERE Id = ?;], parameters=[[1]]])
List of the 8 FullName between 10 and 30 yeras old.
tiffa, mike  26 years old
tiffa, paul  25 years old
tiffa, neo  28 years old
tiffa, neo  23 years old
tiffa, honey  21 years old
larochelle, benoit  27 years old
mastermind, neo  26 years old
trigga, mike  25 years old
Go to the top of the page
+Quote Post

Munkon
**



post 7 Sep, 2009 - 02:19 PM
Post #3
Hi pbl,

This is the tutorial I've been looking for!
Thank you very much for the time and effort..

Unfortunatly, the code is not finished,

the LastNameTable code is cut and the FullNameTable code is missing..
In addition, there is no single main method in this tutorial..

Please, I need the rest of it..

Thanks again..

Munkon.
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 03:13PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month